commit 392d859f3a7c550c1974b24db684e053dde62a9e
Author: Georg Troska <georg.troska@uni-dortmund.de>
Date:   Mon Feb 29 23:46:22 2016 +0100

    Implemented more functionalities to box-plots

diff --git a/hist/histpainter/inc/THistPainter.h b/hist/histpainter/inc/THistPainter.h
index 2ccf4df..4e01a13 100644
--- a/hist/histpainter/inc/THistPainter.h
+++ b/hist/histpainter/inc/THistPainter.h
@@ -89,6 +89,10 @@ public:
    virtual void       PaintBarH(Option_t *option);
    virtual void       PaintBoxes(Option_t *option);
    virtual void       PaintCandlePlot(Option_t *option);
+   
+   virtual void       PaintOneCandle(Double_t candlePosition, Double_t candleWidth, TH1 *proj, TH1 *drawHisto);
+   virtual void		  PaintOneLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, bool swapXY = false);
+   
    virtual void       PaintViolinPlot(Option_t *option);
    virtual void       PaintColorLevels(Option_t *option);
    virtual void       PaintColorLevelsFast(Option_t *option);
diff --git a/hist/histpainter/src/THistPainter.cxx b/hist/histpainter/src/THistPainter.cxx
index 6d73c6b..caa07b1 100644
--- a/hist/histpainter/src/THistPainter.cxx
+++ b/hist/histpainter/src/THistPainter.cxx
@@ -3251,13 +3251,57 @@ Int_t THistPainter::MakeChopt(Option_t *choptin)
 
    l = strstr(chopt,"CANDLE");
    if (l) {
-      Hoption.Scat = 0;
-      Hoption.Candle = 1;
-      strncpy(l,"   ",6);
-      if (l[6] == 'X') { Hoption.Candle = 1; l[6] = ' '; }
-      if (l[6] == 'Y') { Hoption.Candle = 2; l[6] = ' '; }
-   }
-
+	Hoption.Scat = 0;
+	Hoption.Candle = 1; // bit 0 is always on!
+	strncpy(l,"      ",6);
+
+	if (l[6] == 'X') { Hoption.Candle &= ~(1 << 1); l[6] = ' '; } // Set bit 1 to 0
+	if (l[6] == 'Y') { Hoption.Candle |= (1 << 1); l[6] = ' '; } // Set bit 1 to 1
+	if (l[7] == '1') { 
+		Hoption.Candle |= (1 << 4) | (3 << 6) | (1 << 11);
+		l[7] = ' '; 
+	} 
+	if (l[7] == '2') { 
+		Hoption.Candle |= (1 << 2) | (1 << 4) | (1 << 6) | (1 << 8) | (1 << 11);
+		l[7] = ' ';
+	}
+	if (l[7] == '3') { 
+		Hoption.Candle |= (1 << 2) | (2 << 4) | (1 << 6) | (1 << 8) | (1 << 11);
+		l[7] = ' ';
+	}
+	Int_t bs=0;
+	
+	l = strstr(chopt,"OPT(");
+	if (l) {
+		if (sscanf(&l[4],"%d",&bs) > 0) {
+			Int_t i=0;
+			while (l[i]!=')') {
+				l[i] = ' ';
+				i++;
+			}
+			l[i] = ' ';
+		}
+		Hoption.Candle = bs;
+		Hoption.Candle |= 1;
+		std::cout << "Candleoption is: " << Hoption.Candle << std::endl;
+	}
+	
+		/*
+		 * BIT-DESCIPTION for Hoption.Candle
+		 * 0:     always on
+		 * 1:     0 - X, 1 - Y
+		 * 2-3:   0: standard whisker, 1: 1.5*iqr, 2:free, 3:free
+		 * 4-5:   0: no median, 1: median as line, 2: median with errors, 3: median as circle
+		 * 6-7:   0: no mean, 1: mean as dashed line, 2: free, 3: mean as circle
+		 * 8:     0: no outliers, 1: outliers
+		 * 9:     0: do not show values within iqr, 1: show all values within iqr + outliers
+		 * 10:    0: show outliers and all values in the candle line, 1: show them randomly
+		 * 11-12: 0: no anker, 1: standard anker, 2: free, 3: free 
+		*/
+	
+		
+   }
+   
    l = strstr(chopt,"VIOLIN");
    if (l) {
       Hoption.Scat = 0;
@@ -4414,163 +4458,378 @@ void THistPainter::PaintBoxes(Option_t *)
    fH->TAttFill::Modify();
 }
 
-////////////////////////////////////////////////////////////////////////////////
-/// [Control function to draw a 2D histogram as a candle (box) plot.](#HP14)
 
-void THistPainter::PaintCandlePlot(Option_t *)
-{
-   Double_t x,y,w;
-   Double_t m1 = 0.055, m2 = 0.25;
-   Double_t xpm[1], ypm[1];
-
-   TH1D *hp;
-   TH2D *h2 = (TH2D*)fH;
-
-   Double_t *quantiles = new Double_t[5];
-   quantiles[0]=0.; quantiles[1]=0.; quantiles[2] = 0.; quantiles[3] = 0.; quantiles[4] = 0.;
-   Double_t *prob = new Double_t[5];
-   prob[0]=1E-15; prob[1]=0.25; prob[2]=0.5; prob[3]=0.75; prob[4]=1-1E-15;
+void THistPainter::PaintOneLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, bool swapXY) {
+	bool doLogY = (!(swapXY) && Hoption.Logy) || (swapXY && Hoption.Logx);
+	bool doLogX = (!(swapXY) && Hoption.Logx) || (swapXY && Hoption.Logy);
+	if (doLogY) {
+		if (y1 > 0) y1 = TMath::Log10(y1); else return; 
+		if (y2 > 0) y2 = TMath::Log10(y2); else return; 
+	}
+	if (doLogX) {
+		if (x1 > 0) x1 = TMath::Log10(x1); else return; 
+		if (x2 > 0) x2 = TMath::Log10(x2); else return; 
+	}
+	if (!swapXY) {
+		gPad->PaintLine(x1, y1, x2, y2);
+	} else {
+		gPad->PaintLine(y1, x1, y2, x2);
+	}
+}
 
-   Style_t fillsav   = h2->GetFillStyle();
-   Style_t colsav    = h2->GetFillColor();
-   Style_t linesav   = h2->GetLineStyle();
-   Style_t widthsav  = h2->GetLineWidth();
-   Style_t pmssav    = h2->GetMarkerStyle();
+void THistPainter::PaintOneCandle(Double_t candlePosition, Double_t candleWidth, TH1 *proj, TH1 *drawHisto) {
+	//std::cout << "Option: " << option << " position: " << position << std::endl;
+	
+	/* A few words about box-plots
+	 * ===========================
+	 * In most cases boxplots are not usefull. Unfortunately they are being used very often when a scattered histogram or something similar 
+	 * would be much better for interpreting data correctly. The candle reduced the information comming from a whole distribution into only 
+	 * very few values. Inpedentend from the number of entries the significance of the underlying distribution a candle will always look like 
+	 * a candle. So be very careful when using a box-plot if you are not sure how your distribution looks like. The main reason, why people 
+	 * like box-plots is the fact that it is much simpler to explain someone the meaning of these candles instead of explaining a 
+	 * two-dimensional histogram.
+	 * 
+	 * In addition to that the calulation of the candles is not done 100% correctly here. The definition of a candle is based on unbinned 
+	 * data. Here we are creating candles out of binned data. Because of this the deviation is connected to the binwidth you are using. 
+	 * 
+	 * The calculation of the quantiles should be done properly on unbinned data as well but is been done on binned, and will only work 
+	 * correctly if the bins where the quantiles are expected are != 0.
+	 * 
+	 * Because of all these facts take care that:
+	 * ------------------------------------------
+	 * * you are using enough points per candle
+	 * * your bin-width is small enough (more bins will increase the maximum avaible resolution of the quantiles altough you will have certain 
+	 * bins with no entries)
+	 * * never make a candle plot is the underlying distribution is double-distributed
+	 * * only create candles of distributions that are more-or-less gaussian (the MPV should be not too far away from the mean, e.g. a -x² 
+	 * distribution in a candle chart would show complete non-sense
+	 * 
+	 * What a candle is made of:
+	 * -------------------------
+	 * A candle represents the quantiles of an underlying distribution. The median, the +-25% reagion (so called inter-quantile-range, or iqr) 
+	 * and the mean can be represented. In Addition to that whiskers are shown. There is a simple definition where the whiskers show the range 
+	 * of the distribution (in this definition the whiskerlines are dashed) and a better distribution where the whiskers are max 1.5*iqr (but 
+	 * never more than the range). In this illustration outliers (showing every datapoints which are not covered by the iqr or the whiskers) 
+	 * are shown individually. 
+	 * It is possible to show all datapoints belonging to a candle, the points can be arrages along the candle or scatted along the candle
+	 * 
+	 * 
+	 * 
+	 * The candle features:
+	 * --------------------
+	 * There are plenty candle feature available now, use them with care. If you use only very little data per candle (~10 datapoints) it will 
+	 * be good to show all datapoints along the candle. Do not show the uncertainty of the mean (it will be larger than the iqr itself and 
+	 * the candles look bad in that case). If your statistics is so high, that you cannot visualize all datapoints anymore show only the 
+	 * outliers - in best case along the candle. With more data inside (~100-500) you will be able to visualize the uncertainly of the median.
+	 * When using very high statistics you can use the random pattern to illustrate an underlying scatter plot. 
+	 * How to illistrate median and mean is up to you, simply take care that mean and median can be distinguished (you can make both appear as 
+	 * circle).
+	 * 
+	 * The bits for Hoption.Candle
+	 * ---------------------------
+	 * 0: always on
+	 * 1: 0 - X, 1 - Y
+	 * 2-3: 0: standard whisker, 1: 1.5*iqr, 2:free, 3:free
+	 * 4-5: 0: no median, 1: median as line, 2: median with errors, 3: median as circle
+	 * 6-7: 0: no mean, 1: mean as dashed line, 2: free, 3: mean as circle
+	 * 8: 0: no outliers, 1: outliers
+	 * 9: 0: do not show values within iqr, 1: show all values within iqr + outliers
+	 * 10: 0: show outliers and all values in the candle line, 1: show them randomly
+	 * 11-12: 0: no anker, 1: standard anker, 2: free, 3: free 
+	*/
+		
+		
+      
+	/* Remembering the values from the original histo */
+	Style_t saveFill   		= drawHisto->GetFillStyle();
+	Style_t saveColor   	= drawHisto->GetFillColor();
+	Style_t saveLine   		= drawHisto->GetLineStyle();
+	Style_t saveWidth  		= drawHisto->GetLineWidth();
+	Style_t saveMarker    	= drawHisto->GetMarkerStyle();
+	
+	//if (drawHisto->GetFillColor() == 0) drawHisto->SetFillStyle(0);
+		
+	/* Determining the quantiles */
+	Double_t *prob = new Double_t[5];
+	prob[0]=1E-15; prob[1]=0.25; prob[2]=0.5; prob[3]=0.75; prob[4]=1-1E-15;
+	Double_t *quantiles = new Double_t[5];
+	quantiles[0]=0.; quantiles[1]=0.; quantiles[2] = 0.; quantiles[3] = 0.; quantiles[4] = 0.;
+	
+	proj->GetQuantiles(5, quantiles, prob);
+	Double_t iqr = quantiles[3]-quantiles[1];
+	//std::cout << "Quantiles are: " << quantiles[0] << " " << quantiles[1] << " " << quantiles[2] << " " << quantiles[3] << " "<< quantiles[4] << std::endl;
+	
+	//Check if the quantiles are valid, seems the under- and overflow is taken into account as well, we need to ignore this!
+	if (quantiles[0] >= quantiles[4]) return;
+	if (quantiles[1] >= quantiles[3]) return;
+	
+	
+	//Definition of the candle in the standard case
+	Double_t boxHigh = quantiles[3];
+	Double_t boxLow = quantiles[1];
+	Double_t whiskerUpper = quantiles[4]; //Standard case
+	Double_t whiskerLower = quantiles[0]; //Standard case
+	Double_t dimLeft = candlePosition-0.5*candleWidth;
+	Double_t dimRight = candlePosition+0.5*candleWidth;
+	Double_t median = quantiles[2];
+	Double_t mean = proj->GetMean();
+	Double_t medianErr = 1.57*iqr/sqrt(proj->GetEntries());
+	
+	drawHisto->SetMarkerColor(drawHisto->GetLineColor());
+	drawHisto->TAttLine::Modify();
+	
+	bool swapXY = ((Hoption.Candle >> 1) & 0x01);
+	bool doLogY = (!(swapXY) && Hoption.Logy) || (swapXY && Hoption.Logx);
+	bool doLogX = (!(swapXY) && Hoption.Logx) || (swapXY && Hoption.Logy);
+	
+	
+		
+	if (((Hoption.Candle >> 2) & 0x03) == 0x01) { // Improved whisker definition, with 1.5*iqr
+		int bin = proj->FindBin(boxLow-1.5*iqr);
+		//extending only to the lowest data value within this range
+		while (proj->GetBinContent(bin) == 0 && bin <= proj->GetNbinsX()) bin++;
+		whiskerLower = proj->GetBinCenter(bin);
+
+		bin = proj->FindBin(boxHigh+1.5*iqr);
+		while (proj->GetBinContent(bin) == 0 && bin >= 1) bin--;
+		whiskerUpper = proj->GetBinCenter(bin);
+	}
+		
+		if (((Hoption.Candle >> 4) & 0x03) == 0x02) { //check if we have to draw a box with kinks
+			//top and bottom
+			PaintOneLine(dimLeft, boxHigh, dimRight, boxHigh, swapXY);
+			PaintOneLine(dimLeft, boxLow, dimRight, boxLow, swapXY);
+			
+			//the sides
+			PaintOneLine(dimLeft, boxHigh, dimLeft, median+medianErr, swapXY);
+			PaintOneLine(dimLeft, median-medianErr, dimLeft, boxLow, swapXY);
+			PaintOneLine(dimRight, boxHigh, dimRight, median+medianErr, swapXY);
+			PaintOneLine(dimRight, median-medianErr, dimRight, boxLow, swapXY);
+			
+			//the kinks
+			PaintOneLine(dimRight, median+medianErr, dimRight-candleWidth/3., median, swapXY);
+			PaintOneLine(dimRight, median-medianErr, dimRight-candleWidth/3., median, swapXY);
+			PaintOneLine(dimLeft, median+medianErr, dimLeft+candleWidth/3., median, swapXY);
+			PaintOneLine(dimLeft, median-medianErr, dimLeft+candleWidth/3., median, swapXY);
+			
+			
+		} else { // draw a simple box 
+			//top and bottom
+			PaintOneLine(dimLeft, boxHigh, dimRight, boxHigh, swapXY);
+			PaintOneLine(dimLeft, boxLow, dimRight, boxLow, swapXY);
+			//the sides
+			PaintOneLine(dimLeft, boxHigh, dimLeft, boxLow, swapXY);
+			PaintOneLine(dimRight, boxHigh, dimRight, boxLow, swapXY);
+		}
+		
+		if (((Hoption.Candle >> 11) & 0x03) == 0x01) { //Yes, draw the anker line
+			PaintOneLine(dimLeft, whiskerUpper, dimRight, whiskerUpper, swapXY);
+			PaintOneLine(dimLeft, whiskerLower, dimRight, whiskerLower, swapXY); 
+		}
+        
+        if (!((Hoption.Candle >> 2) & 0x03)) { //whiskers are dashed
+			drawHisto->SetLineStyle(2);
+			drawHisto->TAttLine::Modify();
+			PaintOneLine(candlePosition, whiskerUpper, candlePosition, boxHigh, swapXY); 
+			PaintOneLine(candlePosition, boxLow, candlePosition, whiskerLower, swapXY);
+			drawHisto->SetLineStyle(saveLine);
+			drawHisto->TAttLine::Modify();
+		} else { //whiskers without dashing
+			PaintOneLine(candlePosition, whiskerUpper, candlePosition, boxHigh, swapXY); 
+			PaintOneLine(candlePosition, boxLow, candlePosition, whiskerLower, swapXY);
+		}
+       
+                
+		if ((( Hoption.Candle >> 4) & 0x03) == 0x01 ) { //Paint median as a line
+			PaintOneLine(dimLeft, median, dimRight, median, swapXY); 
+		} else if ((( Hoption.Candle >> 4) & 0x03) == 0x02 ) { //Paint median as a line (using kinks)
+			PaintOneLine(dimLeft+candleWidth/3, median, dimRight-candleWidth/3., median, swapXY); 
+		} else if ((( Hoption.Candle >> 4) & 0x03) == 0x03 ) { //Paint median circle
+			Double_t myMedianX[1], myMedianY[1];
+			if (!swapXY) {
+				myMedianX[0] = candlePosition;
+				myMedianY[0] = median;
+			} else {
+				myMedianX[0] = median;
+				myMedianY[0] = candlePosition;
+			}
+			
+			bool isValid = true;
+			if (doLogX) {
+				if (myMedianX[0] > 0) myMedianX[0] = TMath::Log10(myMedianX[0]); else isValid = false;
+			}
+			if (doLogY) {
+				if (myMedianY[0] > 0) myMedianY[0] = TMath::Log10(myMedianY[0]); else isValid = false;
+			}
+			
+			
+			drawHisto->SetMarkerStyle(24);
+			drawHisto->SetMarkerColor(drawHisto->GetLineColor());
+			drawHisto->TAttMarker::Modify();
+			if (isValid) gPad->PaintPolyMarker(1,myMedianX,myMedianY); // a circle for the median
+			drawHisto->SetMarkerStyle(saveMarker);
+			drawHisto->TAttMarker::Modify();
+		}
+        if ((( Hoption.Candle >> 6) & 0x03) == 0x03 ) { //Paint mean as a circle
+			
+			Double_t myMeanX[1], myMeanY[1];
+			if (!swapXY) {
+				myMeanX[0] = candlePosition;
+				myMeanY[0] = mean;
+			} else {
+				myMeanX[0] = mean;
+				myMeanY[0] = candlePosition;
+			}
+			
+			bool isValid = true;
+			if (doLogX) {
+				if (myMeanX[0] > 0) myMeanX[0] = TMath::Log10(myMeanX[0]); else isValid = false;
+			}
+			if (doLogY) {
+				if (myMeanY[0] > 0) myMeanY[0] = TMath::Log10(myMeanY[0]); else isValid = false;
+			}
+			
+			drawHisto->SetMarkerStyle(24);
+			drawHisto->SetMarkerColor(drawHisto->GetLineColor());
+			drawHisto->TAttMarker::Modify();
+			if (isValid) gPad->PaintPolyMarker(1,myMeanX,myMeanY); // a circle for the mean
+			drawHisto->SetMarkerStyle(saveMarker);
+			drawHisto->TAttMarker::Modify();
+			
+			
+		} else if ((( Hoption.Candle >> 6) & 0x03) == 0x01 ) { //Paint mean as a dashed line
+			drawHisto->SetLineStyle(2);
+			drawHisto->TAttLine::Modify();
+			PaintOneLine(dimLeft, mean, dimRight, mean, swapXY); 
+			drawHisto->SetLineStyle(saveLine);
+			drawHisto->TAttLine::Modify();
+			
+		}
+		
+		if (((Hoption.Candle >> 11) & 0x03) == 0x01) { //Draw standard anker
+			
+			PaintOneLine(dimLeft, whiskerLower, dimRight, whiskerLower, swapXY); // the lower anker line
+            PaintOneLine(dimLeft, whiskerUpper, dimRight, whiskerUpper, swapXY); // the upper anker line
+		}
+		
+		
+		/* This is a bit complex. All values here are handled as outliers. Usually only the datapoints outside the whiskers are shown. 
+		 * One can show them in one row as crosses, or scattered randomly. If activated all datapoint are shown in the same way 
+		 */
+		TRandom2 random;
+		if ((Hoption.Candle >> 8) & 0x01) { //Draw outliers
+			const int maxOutliers = kNMAX; //max outliers per candle
+			Double_t outliersX[maxOutliers];
+			Double_t outliersY[maxOutliers];
+			Double_t myScale = 1.;
+			if (proj->GetEntries() > maxOutliers/2) myScale = proj->GetEntries()/(maxOutliers/2.);
+			int nOutliers = 0;
+			for (int bin = 0; bin < proj->GetNbinsX(); bin++) {
+				//either show them only outside the whiskers, or all of them (bit9)
+				 if (proj->GetBinContent(bin) > 0 && (proj->GetBinCenter(bin) < whiskerLower || proj->GetBinCenter(bin) > whiskerUpper || ((Hoption.Candle >> 9) & 0x01)) ) {
+					for (int j=0; j < proj->GetBinContent(bin)/myScale; j++) {
+						if (nOutliers > maxOutliers) break;
+					   
+						if ((Hoption.Candle >> 10) & 0x01) { //Draw outliers and "all" values scattered
+							outliersX[nOutliers] = candlePosition - candleWidth/2. + candleWidth*random.Rndm();	
+							outliersY[nOutliers] = proj->GetBinLowEdge(bin) + proj->GetBinWidth(bin)*random.Rndm();	
+						} else { //Draw them in the "candle line"
+							outliersX[nOutliers] = candlePosition;
+							outliersY[nOutliers] = proj->GetBinCenter(bin);	
+						}
+						
+						if (swapXY) {
+							//Swap X and Y
+							Double_t keepCurrently;
+							keepCurrently = outliersX[nOutliers];
+							outliersX[nOutliers] = outliersY[nOutliers];
+							outliersY[nOutliers] = keepCurrently;
+						}
+						//Continue means, that nOutiers is not increased, so that value will not be shown
+						if (doLogX) {
+							if (outliersX[nOutliers] > 0) outliersX[nOutliers] = TMath::Log10(outliersX[nOutliers]); else continue;
+						}
+						if (doLogY) {
+							if (outliersY[nOutliers] > 0) outliersY[nOutliers] = TMath::Log10(outliersY[nOutliers]); else continue;
+						}
+						
+						nOutliers++;
+						
+					}
+				 }
+				 if (nOutliers > maxOutliers) { //Should never happen, due to myScale!!!
+					 Error ("PaintCandlePlot","Not possible to draw all outliers, usually this means, that your data should not be drawn in a candle chart");
+					 break;
+				 }
+			  }
+			  drawHisto->SetMarkerColor(drawHisto->GetLineColor());
+			  drawHisto->TAttMarker::Modify();
+			  if ((Hoption.Candle >> 10) & 0x01) { //Draw outliers and "all" values scattered
+				  drawHisto->SetMarkerStyle(0);
+			  } else {
+				  drawHisto->SetMarkerStyle(5);
+			  }
+			  drawHisto->TAttMarker::Modify();
+
+			  gPad->PaintPolyMarker(nOutliers,outliersX, outliersY);
+		}
+		
+	
+	//Set everything back to original
+	
+	drawHisto->SetFillStyle(saveFill);
+	drawHisto->SetFillColor(saveColor);
+	drawHisto->SetLineStyle(saveLine);
+	drawHisto->SetMarkerStyle(saveMarker);
+	drawHisto->SetLineWidth(saveWidth);
+	drawHisto->TAttFill::Modify();
+	drawHisto->TAttLine::Modify();
+	drawHisto->TAttMarker::Modify();
+	 
+	 
+	
+	
+}
 
-   if (h2->GetFillColor() == 0)  h2->SetFillStyle(0);
 
-   h2->SetMarkerStyle(24);
-   h2->TAttLine::Modify();
-   h2->TAttFill::Modify();
-   h2->TAttMarker::Modify();
+////////////////////////////////////////////////////////////////////////////////
+/// [Control function to draw a 2D histogram as a candle (box) plot.](#HP14)
 
-   // Candle plot along X
-   Double_t xb1,xb2,yb1,yb2,xl1,xl2,yl1,yl2,xl3,yl3,xp1,yp1;
-   if (Hoption.Candle == 1) {
+void THistPainter::PaintCandlePlot(Option_t *)
+{
+   TH1D *hproj;
+   TH2D *myfH = (TH2D*)fH;
+   
+   bool swapXY = ((Hoption.Candle >> 1) & 0x01);
+   const Double_t standardCandleWidth = 0.66;
+   
+   
+   if (!swapXY) { // Vertical candle 
       for (Int_t i=Hparam.xfirst; i<=Hparam.xlast; i++) {
-         x = fXaxis->GetBinLowEdge(i);
-         w = fXaxis->GetBinWidth(i);
-         hp = h2->ProjectionY("_px", i, i);
-         if (hp->GetEntries() !=0) {
-            hp->GetQuantiles(5, quantiles, prob);
-            yp1 = hp->GetMean();
-            xb1 = x+m1*w;
-            xb2 = x+(1-m1)*w;
-            yb1 = quantiles[1];
-            yb2 = quantiles[3];
-            xl1 = x+m2*w;
-            xl2 = x+(1-m2)*w;
-            yl1 = quantiles[0];
-            yl2 = quantiles[4];
-            yl3 = quantiles[2];
-            xp1 = x+w/2.;
-            if (Hoption.Logy) {
-               if (yb1 > 0)  yb1  = TMath::Log10(yb1); else continue;
-               if (yb2 > 0)  yb2  = TMath::Log10(yb2); else continue;
-               if (yl1 > 0)  yl1  = TMath::Log10(yl1); else continue;
-               if (yl2 > 0)  yl2  = TMath::Log10(yl2); else continue;
-               if (yl3 > 0)  yl3  = TMath::Log10(yl3); else continue;
-               if (yp1 > 0)  yp1  = TMath::Log10(yp1); else continue;
-            }
-            if (Hoption.Logx) {
-               if (xb1 > 0)  xb1  = TMath::Log10(xb1); else continue;
-               if (xb2 > 0)  xb2  = TMath::Log10(xb2); else continue;
-               if (xl1 > 0)  xl1  = TMath::Log10(xl1); else continue;
-               if (xl2 > 0)  xl2  = TMath::Log10(xl2); else continue;
-               if (xp1 > 0)  xp1  = TMath::Log10(xp1); else continue;
-            }
-            ypm[0] = yp1;
-            h2->SetLineStyle(1);
-            h2->TAttLine::Modify();
-            gPad->PaintBox (xb1, yb1, xb2, yb2);
-            gPad->PaintLine(xl1, yl1, xl2, yl1);
-            gPad->PaintLine(xl1, yl2, xl2, yl2);
-            h2->SetLineWidth(3*widthsav);
-            h2->TAttLine::Modify();
-            gPad->PaintLine(xb1, yl3, xb2, yl3);
-            h2->SetLineWidth(widthsav);
-            h2->TAttLine::Modify();
-
-            h2->SetLineStyle(2);
-            h2->TAttLine::Modify();
-            gPad->PaintLine(xp1, yb2, xp1, yl2);
-            gPad->PaintLine(xp1, yl1, xp1, yb1);
-
-            xpm[0] = xp1;
-            gPad->PaintPolyMarker(1,xpm,ypm);
-         }
-      }
-   // Candle plot along Y
-   } else {
-      for (Int_t i=Hparam.yfirst; i<=Hparam.ylast; i++) {
-         y = fYaxis->GetBinLowEdge(i);
-         w = fYaxis->GetBinWidth(i);
-         hp = h2->ProjectionX("_py", i, i);
-         if (hp->GetEntries() !=0) {
-            hp->GetQuantiles(5, quantiles, prob);
-            xp1 = hp->GetMean();
-            yb1 = y+m1*w;
-            yb2 = y+(1-m1)*w;
-            xb1 = quantiles[1];
-            xb2 = quantiles[3];
-            yl1 = y+m2*w;
-            yl2 = y+(1-m2)*w;
-            xl1 = quantiles[0];
-            xl2 = quantiles[4];
-            xl3 = quantiles[2];
-            yp1 = y+w/2.;
-            if (Hoption.Logx) {
-               if (xb1 > 0)  xb1  = TMath::Log10(xb1); else continue;
-               if (xb2 > 0)  xb2  = TMath::Log10(xb2); else continue;
-               if (xl1 > 0)  xl1  = TMath::Log10(xl1); else continue;
-               if (xl2 > 0)  xl2  = TMath::Log10(xl2); else continue;
-               if (xl3 > 0)  xl3  = TMath::Log10(xl3); else continue;
-               if (xp1 > 0)  xp1  = TMath::Log10(xp1); else continue;
-            }
-            if (Hoption.Logy) {
-               if (yb1 > 0)  yb1  = TMath::Log10(yb1); else continue;
-               if (yb2 > 0)  yb2  = TMath::Log10(yb2); else continue;
-               if (yl1 > 0)  yl1  = TMath::Log10(yl1); else continue;
-               if (yl2 > 0)  yl2  = TMath::Log10(yl2); else continue;
-               if (yp1 > 0)  yp1  = TMath::Log10(yp1); else continue;
-            }
-            xpm[0] = xp1;
-            h2->SetLineStyle(1);
-            h2->TAttLine::Modify();
-
-            gPad->PaintBox (xb1, yb1, xb2, yb2);
-            gPad->PaintLine(xl1, yl1, xl1, yl2);
-            gPad->PaintLine(xl2, yl1, xl2, yl2);
-
-            h2->SetLineWidth(3*widthsav);
-            h2->TAttLine::Modify();
-            gPad->PaintLine(xl3, yb1, xl3, yb2);
-
-            h2->SetLineWidth(widthsav);
-            h2->TAttLine::Modify();
-
-            h2->SetLineStyle(2);
-            h2->TAttLine::Modify();
-            gPad->PaintLine(xb2, yp1, xl2, yp1);
-            gPad->PaintLine(xl1, yp1, xb1, yp1);
-
-            ypm[0] = yp1;
-            gPad->PaintPolyMarker(1,xpm,ypm);
-         }
-      }
-   }
-
-   h2->SetFillStyle(fillsav);
-   h2->SetFillColor(colsav);
-   h2->SetLineStyle(linesav);
-   h2->SetMarkerStyle(pmssav);
-   h2->SetLineWidth(widthsav);
-   h2->TAttFill::Modify();
-   h2->TAttLine::Modify();
-   h2->TAttMarker::Modify();
-
-   delete [] prob;
-   delete [] quantiles;
+         Double_t binPosX = fXaxis->GetBinLowEdge(i);
+         Double_t binWidth = fXaxis->GetBinWidth(i);
+         hproj = myfH->ProjectionY("_px", i, i);
+         if (hproj->GetEntries() !=0) {
+			 Double_t width = myfH->GetBarWidth();
+			 Double_t offset = myfH->GetBarOffset()*binWidth;
+			 if (width > 0.999) width = standardCandleWidth;
+			 PaintOneCandle(binPosX+binWidth/2. + offset ,width*binWidth,hproj,myfH);
+		 }
+	 }
+ } else { //horizontal candle
+	 for (Int_t i=Hparam.yfirst; i<=Hparam.ylast; i++) {
+         Double_t binPosY = fYaxis->GetBinLowEdge(i);
+         Double_t binWidth = fYaxis->GetBinWidth(i);
+         hproj = myfH->ProjectionX("_py", i, i);
+         if (hproj->GetEntries() !=0) {
+			 Double_t width = myfH->GetBarWidth();
+			 Double_t offset = myfH->GetBarOffset()*binWidth;
+			 if (width > 0.999) width = standardCandleWidth;
+			 PaintOneCandle(binPosY+binWidth/2. + offset ,width*binWidth,hproj,myfH);
+		 }
+	 }
+ }
+           
 }
 
 ////////////////////////////////////////////////////////////////////////////////
