/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooLinTransBinning.h,v 1.9 2007/05/11 09:11:30 verkerke Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_LIN_TRANS_BINNING
#define ROO_LIN_TRANS_BINNING

#include "Rtypes.h"
#include "RooAbsBinning.h"

class RooLinTransBinning : public RooAbsBinning {
public:

  RooLinTransBinning(const char* name=0) : RooAbsBinning(name) {
    // coverity[UNINIT_CTOR]
  } ; 
  RooLinTransBinning(const RooAbsBinning& input, Double_t slope=1.0, Double_t offset=0.0, const char* name=0) ;
  RooLinTransBinning(const RooLinTransBinning&, const char* name=0) ;
  virtual RooAbsBinning* clone(const char* name=0) const { return new RooLinTransBinning(*this,name) ; }
  virtual ~RooLinTransBinning() ;

  virtual Int_t numBoundaries() const { return _input->numBoundaries() ; }
  virtual Int_t binNumber(Double_t x) const { return _input->binNumber(invTrans(x)) ; }
  virtual Double_t binCenter(Int_t bin) const { return trans(_input->binCenter(binTrans(bin))) ; }
  virtual Double_t binWidth(Int_t bin) const { return _slope*_input->binWidth(binTrans(bin)) ; }
  virtual Double_t binLow(Int_t bin) const { if (_slope>0) return trans(_input->binLow(binTrans(bin))) ; else return trans(_input->binHigh(binTrans(bin))) ; }
  virtual Double_t binHigh(Int_t bin) const { if (_slope>0) return trans(_input->binHigh(binTrans(bin))) ; else return trans(_input->binLow(binTrans(bin))) ; }

  virtual void setRange(Double_t xlo, Double_t xhi) ;
  virtual void setMin(Double_t xlo) { setRange(xlo,highBound()) ; }
  virtual void setMax(Double_t xhi) { setRange(lowBound(),xhi) ; }

  virtual Double_t lowBound() const { if (_slope>0) return trans(_input->lowBound()) ; else return trans(_input->highBound()) ; }
  virtual Double_t highBound() const { if (_slope>0) return trans(_input->highBound()) ; else return trans(_input->lowBound()) ; }
  virtual Double_t averageBinWidth() const { return _slope*_input->averageBinWidth() ; }

  virtual Double_t* array() const ;

  void updateInput(const RooAbsBinning& input, Double_t slope=1.0, Double_t offset=0.0) ;

protected:
    
  inline Int_t binTrans(Int_t bin) const { if (_slope>0) return bin ; else return numBins()-bin-1 ; }
  inline Double_t trans(Double_t x) const { return x*_slope + _offset ; }
  inline Double_t invTrans(Double_t x) const { if (_slope==0.) return 0 ; return (x-_offset)/_slope ; }

  Double_t _slope ;         // Slope of transformation
  Double_t _offset ;        // Offset of tranformation
  RooAbsBinning* _input ;   // Input binning
  mutable Double_t *_array ; //! Array of transformed bin boundaries

  ClassDef(RooLinTransBinning,1) // Linear transformation of binning specification
};

#endif
 RooLinTransBinning.h:1
 RooLinTransBinning.h:2
 RooLinTransBinning.h:3
 RooLinTransBinning.h:4
 RooLinTransBinning.h:5
 RooLinTransBinning.h:6
 RooLinTransBinning.h:7
 RooLinTransBinning.h:8
 RooLinTransBinning.h:9
 RooLinTransBinning.h:10
 RooLinTransBinning.h:11
 RooLinTransBinning.h:12
 RooLinTransBinning.h:13
 RooLinTransBinning.h:14
 RooLinTransBinning.h:15
 RooLinTransBinning.h:16
 RooLinTransBinning.h:17
 RooLinTransBinning.h:18
 RooLinTransBinning.h:19
 RooLinTransBinning.h:20
 RooLinTransBinning.h:21
 RooLinTransBinning.h:22
 RooLinTransBinning.h:23
 RooLinTransBinning.h:24
 RooLinTransBinning.h:25
 RooLinTransBinning.h:26
 RooLinTransBinning.h:27
 RooLinTransBinning.h:28
 RooLinTransBinning.h:29
 RooLinTransBinning.h:30
 RooLinTransBinning.h:31
 RooLinTransBinning.h:32
 RooLinTransBinning.h:33
 RooLinTransBinning.h:34
 RooLinTransBinning.h:35
 RooLinTransBinning.h:36
 RooLinTransBinning.h:37
 RooLinTransBinning.h:38
 RooLinTransBinning.h:39
 RooLinTransBinning.h:40
 RooLinTransBinning.h:41
 RooLinTransBinning.h:42
 RooLinTransBinning.h:43
 RooLinTransBinning.h:44
 RooLinTransBinning.h:45
 RooLinTransBinning.h:46
 RooLinTransBinning.h:47
 RooLinTransBinning.h:48
 RooLinTransBinning.h:49
 RooLinTransBinning.h:50
 RooLinTransBinning.h:51
 RooLinTransBinning.h:52
 RooLinTransBinning.h:53
 RooLinTransBinning.h:54
 RooLinTransBinning.h:55
 RooLinTransBinning.h:56
 RooLinTransBinning.h:57
 RooLinTransBinning.h:58
 RooLinTransBinning.h:59
 RooLinTransBinning.h:60
 RooLinTransBinning.h:61
 RooLinTransBinning.h:62
 RooLinTransBinning.h:63
 RooLinTransBinning.h:64
 RooLinTransBinning.h:65
 RooLinTransBinning.h:66