1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliMUONSparseHisto.h"
20 #include <Riostream.h>
25 /// \class AliMUONSparseHisto
27 /// Tiny histogram-like class to hold some distributions of tracker data.
28 /// Only intent of this class is to minimize memory consumption, in
29 /// order to fit a maximum number of channel histograms into memory.
30 /// The rest is not supported ;-)
32 /// \author Laurent Aphecetche, Subatech
35 ClassImp(AliMUONSparseHisto)
38 //______________________________________________________________________________
39 AliMUONSparseHisto::AliMUONSparseHisto(Double_t xmin, Double_t xmax)
45 fFactor((1<<Nbits())/(xmax-xmin))
52 //______________________________________________________________________________
53 AliMUONSparseHisto::AliMUONSparseHisto(const AliMUONSparseHisto& rhs)
65 //______________________________________________________________________________
67 AliMUONSparseHisto::operator=(const AliMUONSparseHisto& rhs)
69 /// assignment operator
77 //______________________________________________________________________________
78 AliMUONSparseHisto::~AliMUONSparseHisto()
84 //______________________________________________________________________________
86 AliMUONSparseHisto::Clear(Option_t*)
94 //______________________________________________________________________________
96 AliMUONSparseHisto::Copy(TObject& object) const
98 /// Copy this to *object
99 TObject::Copy(object);
100 AliMUONSparseHisto& h = static_cast<AliMUONSparseHisto&>(object);
103 h.fNbins = GetNbins();
106 h.fFactor = Factor();
108 if ( GetNbins() > 0 )
110 h.fArray = new UInt_t[GetNbins()];
111 for ( Int_t i = 0; i < GetNbins(); ++i )
113 h.fArray[i] = GetBin(i);
118 //______________________________________________________________________________
120 AliMUONSparseHisto::DecodeValue(Int_t value) const
122 /// From internal integer to "original" double
123 return value/Factor() + Xmin();
126 //______________________________________________________________________________
128 AliMUONSparseHisto::EncodeValue(Double_t value) const
130 /// From original double value to internal integer
131 return TMath::Nint(Factor()*(value-Xmin()));
134 //______________________________________________________________________________
136 AliMUONSparseHisto::BinCenter(UInt_t x) const
138 /// Extract binCenter part from x
140 return ( x & 0xFFF00000 ) >> 20;
143 //______________________________________________________________________________
145 AliMUONSparseHisto::BinContent(UInt_t x) const
147 /// Extract binContent part from x
149 return (x & 0xFFFFF);
152 //______________________________________________________________________________
154 AliMUONSparseHisto::Encode(Int_t binCenter, Int_t binContent) const
156 /// Convert (binCenter,binContent) into a single value
158 return ( ( binCenter & 0xFFF ) ) << 20 | ( ( binContent & 0xFFFFF ) );
161 //______________________________________________________________________________
163 AliMUONSparseHisto::Expand()
165 /// Make fArray of size n
166 if (!fArray || !fNbins)
169 fArray = new UInt_t[1];
174 UInt_t* tmp = new UInt_t[fNbins+1];
175 for ( Int_t i = 0; i < fNbins; ++i )
185 //______________________________________________________________________________
187 AliMUONSparseHisto::Fill(Double_t value)
191 if ( value < Xmin() )
193 SetBit(kUnderflow,1);
197 if ( value > Xmax() )
203 Int_t ivalue = EncodeValue(value);
205 Int_t i = Find(ivalue);
211 fArray[n] = Encode(ivalue,1);
216 Int_t bc = GetBinContent(i);
219 fArray[i] = Encode(ivalue,bc+1);
226 //______________________________________________________________________________
228 AliMUONSparseHisto::Find(Int_t binCenter) const
230 /// Return the index in fArray of value, or -1 if not found
232 for ( Int_t i = 0; i < GetNbins(); ++i )
234 if ( binCenter == GetBinCenter(i) ) return i;
239 //______________________________________________________________________________
241 AliMUONSparseHisto::GetBin(Int_t bin) const
243 /// Get bin, which is a compacted form of two integers : (binCenter,binContent)
244 /// where binCenter itself might be an integer-fied double value.
248 //______________________________________________________________________________
250 AliMUONSparseHisto::GetBinCenter(Int_t bin) const
253 if ( bin < 0 ) return -FLT_MAX;
254 if ( bin >= GetNbins() ) return FLT_MAX;
256 UInt_t i = GetBin(bin);
258 return DecodeValue(BinCenter(i));
261 //______________________________________________________________________________
263 AliMUONSparseHisto::GetBinContent(Int_t bin) const
267 if ( bin < 0 || bin >= GetNbins() ) return 0xFFFFFFFF;
269 UInt_t i = GetBin(bin);
271 return BinContent(i);
274 //______________________________________________________________________________
276 AliMUONSparseHisto::Print(Option_t* opt) const
279 Int_t id1 = ( GetUniqueID() & 0xFFFF0000 ) >> 16;
280 Int_t id2 = GetUniqueID() & 0xFFFF;
282 cout << "ID=(" << id1 << "," << id2 << ") n bins = " << GetNbins();
283 if ( HasUnderflow() ) cout << " has underflow(s)";
284 if ( HasOverflow() ) cout << " has overflow(s)";
290 if ( sopt.Contains("FULL") )
292 for ( Int_t i = 0; i < GetNbins(); ++i )
294 cout << Form("Bin (%10u) %e = %6d",GetBin(i),GetBinCenter(i),GetBinContent(i)) << endl;