AliPhysics  48852ec (48852ec)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliFMDEncodedEdx.h
Go to the documentation of this file.
1 #ifndef ALIFMDENCODEDEDX_H
2 #define ALIFMDENCODEDEDX_H
3 
11 #ifndef __CINT__
12 # include <TMath.h>
13 # include <TArrayD.h>
14 # include <TH1D.h>
15 # include <TH2D.h>
16 #else
17 class TArrayD;
18 class TH1;
19 class TH2;
20 #endif
21 
53 {
54 public:
59  struct Spec {
60  UShort_t nBins; // Total number of bins
61  Double_t min; // Least value
62  Double_t max; // Largest value
63  UShort_t cutBin1; // Last bin (plus one) of lower region
64  Double_t cutVal1; // Upper cut on lower region
65  UShort_t cutBin2; // Last bin (plus one) of middle region
66  Double_t cutVal2; // Upper cut on middle region
75  : nBins(nb), min(l), max(h),
76  cutBin1(UShort_t(nb * 0.75 + .5)),
77  cutVal1((max-min) / 10 + min),
78  cutBin2(UShort_t(nb * 0.95 + .5)),
79  cutVal2((max-min) / 5 + min)
80  {}
89  {
90  UInt_t off = 0;
91  UInt_t n = cutBin1;
92  Double_t low = min;
93  Double_t high = cutVal1;
94  if (v > cutVal2) {
95  // Upper part of the plot
96  off = cutBin2;
97  n = nBins - cutBin2;
98  low = cutVal2;
99  high = max;
100  }
101  else if (v > cutVal1) {
102  // Middle part
103  off = cutBin1;
104  n = cutBin2 - cutBin1;
105  low = cutVal1;
106  high = cutVal2;
107  }
108  return off + UInt_t(n*(v-low)/(high-low));
109  }
119  {
120  Double_t off = min;
121  UInt_t n = cutBin1;
122  Double_t high = cutVal1;
123  if (b >= cutBin2) {
124  // Upper part
125  off = cutVal2;
126  n = nBins - cutBin2;
127  high = max;
128  b -= cutBin2;
129  }
130  else if (b >= cutBin1) {
131  // Middle part
132  off = cutVal1;
133  n = cutBin2 - cutBin1;
134  high = cutVal2;
135  b -= cutBin1;
136  }
137  w = (high-off)/n;
138  return off + w * (b+.5);
139  }
148  {
149  Double_t w;
150  return Decode(b, w);
151  }
158  void FillBinArray(TArrayD& a) const
159  {
160  a.Set(nBins+1);
161  a[0] = min;
162  Double_t w0 = (cutVal1 - min) / cutBin1;
163  Double_t w1 = (cutVal2 - cutVal1) / (cutBin2 - cutBin1);
164  Double_t w2 = (max - cutVal2) / (nBins - cutBin2);
165  for (UInt_t i = 1; i <= cutBin1; i++) a[i] = a[i-1] + w0;
166  for (UInt_t i = cutBin1+1; i <= cutBin2; i++) a[i] = a[i-1] + w1;
167  for (UInt_t i = cutBin2+1; i <= nBins; i++) a[i] = a[i-1] + w2;
168  }
174  void Print(Option_t* opt="") const
175  {
176  Printf("Spec: [%8.4f,%8.4f] in %3d bins, cuts %8.4f (%3d) %8.4f (%3d)",
178  if (opt[0] == 'T' || opt[0] == 't') {
179  for (Int_t i = 0; i < nBins; i++) {
180  Double_t w = 0;
181  Double_t x = Decode(i,w );
182  UInt_t j = Encode(x);
183  Printf("%3d -> %8.4f (%7.4f) -> %3d", i, x, w, j);
184  }
185  }
186  }
191  static void Test()
192  {
193  Spec s(125, 0, 125);
194  s.Print("T");
195  }
196  };
200  enum {
201  kNEBits = 8,
202  kNLBits = 5,
203  kEMask = 0xFF, // (1 << kNEBits) - 1
204  kLMask = 0x1F // (1 << kNLBits) - 1
205  };
213  virtual ~AliFMDEncodedEdx() {}
220  static const Spec& GetdEAxis()
221  {
222  static Spec* dEAxis = 0;
223  if (!dEAxis) dEAxis = new Spec((1<<kNEBits), 0 /*0.0000025*/, 11);
224  return *dEAxis;
225  }
232  static const Spec& GetdLAxis()
233  {
234  static Spec* dLAxis = 0;
235  if (!dLAxis) dLAxis = new Spec((1<<kNLBits), 0 /*0.00014*/, 0.7);
236  return *dLAxis;
237  }
246  static UInt_t Encode(Double_t edep, Double_t length)
247  {
248  UInt_t uE = EncodeOne(edep, GetdEAxis());
249  UInt_t uL = EncodeOne(length, GetdLAxis());
250  return (((uE & kEMask) << 0) | ((uL & kLMask) << kNEBits));
251  }
259  static void Decode(UInt_t bits, Double_t& edep, Double_t& length)
260  {
261  edep = DecodeOne((bits >> 0) & kEMask, GetdEAxis());
262  length = DecodeOne((bits >> kNEBits) & kLMask, GetdLAxis());
263  }
273  static void Decode(UInt_t bits, Double_t& edep, Double_t& length,
274  Double_t& wEdep, Double_t& wLength)
275  {
276  edep = DecodeOne((bits >> 0) & kEMask, wEdep, GetdEAxis());
277  length = DecodeOne((bits >> kNEBits) & kLMask, wLength, GetdLAxis());
278  }
290  static TH1* Make1D(const char* name, const char* title, UShort_t mode=true)
291  {
292  const Spec& a = (mode==0 || mode==2 ? GetdEAxis() : GetdLAxis());
293  TArrayD aa; a.FillBinArray(aa);
294 
295  if (mode == 2)
296  // In case we need to do dE/dx, extend the range by a factor 100
297  for (Int_t i = 0; i < aa.GetSize(); i++) aa[i] *= 100;
298 
299  // Make the histogram
300  TH1* h = new TH1D(name, title, aa.GetSize()-1, aa.GetArray());
301  h->SetXTitle(mode == 0 ? "d#Delta [MeV]" :
302  mode == 1 ? "dx [cm]" :
303  mode == 2 ? "d#Delta/dx [MeV/cm]" : "?");
304  h->SetFillStyle(3001);
305  h->SetMarkerStyle(20);
306  h->Sumw2();
307 
308  return h;
309  }
321  static TH2* Make2D(const char* name, const char* title, Bool_t xedep=true)
322  {
323  const Spec& a1 = (xedep ? GetdEAxis() : GetdLAxis());
324  const Spec& a2 = (xedep ? GetdLAxis() : GetdEAxis());
325  TArrayD aa1; a1.FillBinArray(aa1);
326  TArrayD aa2; a2.FillBinArray(aa2);
327  TH2* h = new TH2D(name, title,
328  aa1.GetSize()-1, aa1.GetArray(),
329  aa2.GetSize()-1, aa2.GetArray());
330  h->SetXTitle(xedep ? "d#Delta [MeV]" : "dx [cm]");
331  h->SetYTitle(xedep ? "dx [cm]" : "d#Delta [MeV]");
332  return h;
333  }
347  static Bool_t IsAvailable(UInt_t alirootRev)
348  {
349  const UInt_t target = 60000;
350  return alirootRev >= target;
351  }
352 private:
361  static UInt_t EncodeOne(Double_t v, const Spec& a)
362  {
363  if (v < a.min) return 0;
364  if (v > a.max) return a.nBins;
365  return a.Encode(v);
366  }
375  static Double_t DecodeOne(UInt_t b, const Spec& a)
376  {
377  if (b >= a.nBins) b = a.nBins-1;
378  return a.Decode(b);
379  }
389  static Double_t DecodeOne(UInt_t b, Double_t& w, const Spec& a)
390  {
391  if (b >= a.nBins) b = a.nBins-1;
392  return a.Decode(b, w);
393  }
394 
395  ClassDef(AliFMDEncodedEdx,1); // En-/Decode dE/dx for/from track references
396 };
397 #endif
398 // Local Variables:
399 // mode: C++
400 // End:
static TH1 * Make1D(const char *name, const char *title, UShort_t mode=true)
static TH2 * Make2D(const char *name, const char *title, Bool_t xedep=true)
ClassDef(AliFMDEncodedEdx, 1)
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:27
static Double_t DecodeOne(UInt_t b, Double_t &w, const Spec &a)
static const Spec & GetdEAxis()
Double_t Decode(UInt_t b) const
static UInt_t EncodeOne(Double_t v, const Spec &a)
int Int_t
Definition: External.C:63
static Double_t DecodeOne(UInt_t b, const Spec &a)
unsigned int UInt_t
Definition: External.C:33
Definition: External.C:228
Definition: External.C:212
static void Decode(UInt_t bits, Double_t &edep, Double_t &length)
void FillBinArray(TArrayD &a) const
Int_t mode
Definition: anaM.C:41
static const Spec & GetdLAxis()
Definition: External.C:220
unsigned short UShort_t
Definition: External.C:28
const char Option_t
Definition: External.C:48
Spec(UShort_t nb, Double_t l, Double_t h)
bool Bool_t
Definition: External.C:53
Double_t Decode(UInt_t b, Double_t &w) const
static UInt_t Encode(Double_t edep, Double_t length)
virtual ~AliFMDEncodedEdx()
static Bool_t IsAvailable(UInt_t alirootRev)
static void Decode(UInt_t bits, Double_t &edep, Double_t &length, Double_t &wEdep, Double_t &wLength)
Definition: External.C:196
void Print(Option_t *opt="") const
UInt_t Encode(Double_t v) const