ROOT logo
#ifndef ALIMUONSPARSEHISTO_H
#define ALIMUONSPARSEHISTO_H

/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* See cxx source for full Copyright notice                               */

// $Id$

/// \ingroup calib
/// \class AliMUONSparseHisto
/// \brief A very memory compact histogram to hold some tracker distributions
/// 
// Author Laurent Aphecetche, Subatech

#ifndef ROOT_TObject
#  include "TObject.h"
#endif

class AliMUONSparseHisto : public TObject
{
public:
  
  enum 
  {
    kUnderflow = BIT(20),
    kOverflow = BIT(21)
  };
  
  AliMUONSparseHisto(Double_t xmin=0.0, Double_t xmax=4096.0); 
  AliMUONSparseHisto(const AliMUONSparseHisto& rhs);
  AliMUONSparseHisto& operator=(const AliMUONSparseHisto& rhs);
  
  virtual ~AliMUONSparseHisto();
  
  Bool_t Add(const AliMUONSparseHisto& h);
  
  /// Whether this histogram has underflow values 
  /// (no way to know the number of underflow, though)
  Bool_t HasUnderflow() const { return TestBit(kUnderflow); }
  
  /// Whether this histogram has overflow values  
  /// (no way to know the number of underflow, though)
  Bool_t HasOverflow() const { return TestBit(kOverflow); }
  
  Int_t Fill(Double_t value);
  
  /// Return number of bins we hold
  Int_t GetNbins() const { return fNbins; }

  Double_t GetBinCenter(Int_t bin) const;
  
  Int_t GetBinContent(Int_t bin) const;
  
  virtual void Print(Option_t* opt="") const;
  
  virtual void Clear(Option_t* opt="");
    
  Int_t Find(Int_t binCenter) const;
  
  virtual void Copy(TObject& object) const;

  /// Return max value of bincenter
  Double_t Xmax() const { return fXmax; }
  
  /// Return min value of bincenter
  Double_t Xmin() const { return fXmin; }
  
  /// Number of bits used to code the x-value of the histogram
  Int_t Nbits() const { return 12; }
  
private:
  
  UInt_t Encode(Int_t binCenter, Int_t binContent) const;
  
  Double_t DecodeValue(Int_t value) const;
  
  Int_t EncodeValue(Double_t value) const;
  
  UInt_t GetBin(Int_t i) const;
  
  Int_t BinCenter(UInt_t x) const;
  
  Int_t BinContent(UInt_t x) const;
  
  void Expand();
  
  /// Conversion factor to go from float to int value (for bin content)
  Double_t Factor() const { return fFactor; } 
  
private:

  Int_t fNbins;  ///< number of bins we hold

  /// compacted content = (bin,value)
  UInt_t* fArray; //[fNbins] compacted content = (bin,value)

  Double_t fXmin; ///< min value of bincenter
  Double_t fXmax; ///< max value of bincenter
  
  Double_t fFactor; ///< to go from double to int
  
  ClassDef(AliMUONSparseHisto,2) // Sparse histogram-like class for ADC distributions
};

#endif
 AliMUONSparseHisto.h:1
 AliMUONSparseHisto.h:2
 AliMUONSparseHisto.h:3
 AliMUONSparseHisto.h:4
 AliMUONSparseHisto.h:5
 AliMUONSparseHisto.h:6
 AliMUONSparseHisto.h:7
 AliMUONSparseHisto.h:8
 AliMUONSparseHisto.h:9
 AliMUONSparseHisto.h:10
 AliMUONSparseHisto.h:11
 AliMUONSparseHisto.h:12
 AliMUONSparseHisto.h:13
 AliMUONSparseHisto.h:14
 AliMUONSparseHisto.h:15
 AliMUONSparseHisto.h:16
 AliMUONSparseHisto.h:17
 AliMUONSparseHisto.h:18
 AliMUONSparseHisto.h:19
 AliMUONSparseHisto.h:20
 AliMUONSparseHisto.h:21
 AliMUONSparseHisto.h:22
 AliMUONSparseHisto.h:23
 AliMUONSparseHisto.h:24
 AliMUONSparseHisto.h:25
 AliMUONSparseHisto.h:26
 AliMUONSparseHisto.h:27
 AliMUONSparseHisto.h:28
 AliMUONSparseHisto.h:29
 AliMUONSparseHisto.h:30
 AliMUONSparseHisto.h:31
 AliMUONSparseHisto.h:32
 AliMUONSparseHisto.h:33
 AliMUONSparseHisto.h:34
 AliMUONSparseHisto.h:35
 AliMUONSparseHisto.h:36
 AliMUONSparseHisto.h:37
 AliMUONSparseHisto.h:38
 AliMUONSparseHisto.h:39
 AliMUONSparseHisto.h:40
 AliMUONSparseHisto.h:41
 AliMUONSparseHisto.h:42
 AliMUONSparseHisto.h:43
 AliMUONSparseHisto.h:44
 AliMUONSparseHisto.h:45
 AliMUONSparseHisto.h:46
 AliMUONSparseHisto.h:47
 AliMUONSparseHisto.h:48
 AliMUONSparseHisto.h:49
 AliMUONSparseHisto.h:50
 AliMUONSparseHisto.h:51
 AliMUONSparseHisto.h:52
 AliMUONSparseHisto.h:53
 AliMUONSparseHisto.h:54
 AliMUONSparseHisto.h:55
 AliMUONSparseHisto.h:56
 AliMUONSparseHisto.h:57
 AliMUONSparseHisto.h:58
 AliMUONSparseHisto.h:59
 AliMUONSparseHisto.h:60
 AliMUONSparseHisto.h:61
 AliMUONSparseHisto.h:62
 AliMUONSparseHisto.h:63
 AliMUONSparseHisto.h:64
 AliMUONSparseHisto.h:65
 AliMUONSparseHisto.h:66
 AliMUONSparseHisto.h:67
 AliMUONSparseHisto.h:68
 AliMUONSparseHisto.h:69
 AliMUONSparseHisto.h:70
 AliMUONSparseHisto.h:71
 AliMUONSparseHisto.h:72
 AliMUONSparseHisto.h:73
 AliMUONSparseHisto.h:74
 AliMUONSparseHisto.h:75
 AliMUONSparseHisto.h:76
 AliMUONSparseHisto.h:77
 AliMUONSparseHisto.h:78
 AliMUONSparseHisto.h:79
 AliMUONSparseHisto.h:80
 AliMUONSparseHisto.h:81
 AliMUONSparseHisto.h:82
 AliMUONSparseHisto.h:83
 AliMUONSparseHisto.h:84
 AliMUONSparseHisto.h:85
 AliMUONSparseHisto.h:86
 AliMUONSparseHisto.h:87
 AliMUONSparseHisto.h:88
 AliMUONSparseHisto.h:89
 AliMUONSparseHisto.h:90
 AliMUONSparseHisto.h:91
 AliMUONSparseHisto.h:92
 AliMUONSparseHisto.h:93
 AliMUONSparseHisto.h:94
 AliMUONSparseHisto.h:95
 AliMUONSparseHisto.h:96
 AliMUONSparseHisto.h:97
 AliMUONSparseHisto.h:98
 AliMUONSparseHisto.h:99
 AliMUONSparseHisto.h:100
 AliMUONSparseHisto.h:101
 AliMUONSparseHisto.h:102
 AliMUONSparseHisto.h:103
 AliMUONSparseHisto.h:104
 AliMUONSparseHisto.h:105