CbmRoot
PairAnalysisHistos.h
Go to the documentation of this file.
1 #ifndef PAIRANALYSISHISTOS_H
2 #define PAIRANALYSISHISTOS_H
3 /* Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice */
5 
7 // //
8 // Generic Histogram container with support for groups and filling of groups by passing //
9 // a vector of data //
10 // //
11 // Authors: //
12 // Julian Book <Julian.Book@cern.ch> //
13 // //
15 
16 #include <iostream>
17 
18 #ifdef HAVE_UINT8_T_HEADER_FILE
19 #include <_types/_uint16_t.h>
20 #include <_types/_uint32_t.h>
21 #include <_types/_uint64_t.h>
22 #include <_types/_uint8_t.h>
23 #else
24 #include <stdint.h>
25 #endif
26 
27 #include <Rtypes.h>
28 
29 #include <TNamed.h>
30 // #include <TCollection.h>
31 #include <TBits.h>
32 #include <TFormula.h>
33 #include <TH1.h> //new
34 #include <THashList.h>
35 #include <THnBase.h>
36 #include <THnSparse.h>
37 #include <TList.h> //new
38 #include <TVectorD.h> //Dfwd
39 
40 #include "PairAnalysisHelper.h"
41 #include "PairAnalysisMetaData.h"
42 #include "PairAnalysisVarManager.h"
43 
44 class TH1;
45 class TString;
46 class TList;
47 // class TVectorT<double>;
48 
50 class PairAnalysisHn : public THnSparseF {
51 public:
52  TList* GetListOfFunctions() const { return fFunctions; }
53  inline PairAnalysisHn() : THnSparseF(), fFunctions(new TList) {}
54  inline PairAnalysisHn(const char* name,
55  const char* title,
56  Int_t dim,
57  const Int_t* nbins,
58  const Double_t* xmin = 0,
59  const Double_t* xmax = 0,
60  Int_t chunksize = 1024 * 16)
61  : THnSparseF(name, title, dim, nbins, xmin, xmax, chunksize)
62  , fFunctions(new TList) {}
63 
64  inline ~PairAnalysisHn() {
65  if (fFunctions) {
66  fFunctions->SetBit(kInvalidObject);
67  TObject* obj = 0;
68  while ((obj = fFunctions->First())) {
69  while (fFunctions->Remove(obj)) {}
70  if (!obj->TestBit(kNotDeleted)) { break; }
71  delete obj;
72  obj = 0;
73  }
74  delete fFunctions;
75  fFunctions = 0;
76  }
77  }
78 
79 protected:
80  TList* fFunctions; //->Pointer to list of functions (fits and user)
81 
82 private:
85  ClassDef(PairAnalysisHn,
86  2) // (temporary) class to hold functions in THnSparse
87 };
90 
91  class PairAnalysisHistos : public TNamed {
92 public:
93  PairAnalysisHistos();
94  PairAnalysisHistos(const char* name, const char* title);
95  virtual ~PairAnalysisHistos();
96 
97  enum {
98  kNoAutoFill = 1000000000,
99  kNoProfile = 999,
100  kNoWeights = 998,
101  kNone = 997
102  };
103  enum Eprecision { kFloat = 0, kDouble };
104 
105  // functions for object creation
106  void SetPrecision(Eprecision precision) { fPrecision = precision; }
107  TBits* GetUsedVars() const { return fUsedVars; }
108  void SetReservedWords(const char* words);
109  void AddClass(const char* histClass);
110  TString UserHistogram(const char* histClass, TObject* hist);
111  static void AdaptNameTitle(TH1* hist, const char* histClass);
112  static void AdaptNameTitle(THnBase* hist, const char* histClass);
113  static void StoreVariables(TObject* obj, UInt_t valType[20]);
114  static void StoreVariables(TH1* obj, UInt_t valType[20]);
115  static void StoreVariables(THnBase* obj, UInt_t valType[20]);
116 
117  void UserHistogram(const char* histClass,
118  Int_t ndim,
119  TObjArray* limits,
120  UInt_t* vars,
121  UInt_t valTypeW = kNoWeights);
122  void AddSparse(const char* histClass,
123  Int_t ndim,
124  TObjArray* limits,
125  UInt_t* vars,
126  UInt_t valTypeW = kNoWeights);
127  void AddSparse(const char* histClass,
128  Int_t ndim,
129  TObjArray* limits,
130  TFormula** vars,
131  UInt_t valTypeW = kNoWeights);
132 
133  // templates
134  template<typename valX,
135  typename valY,
136  typename valZ,
137  typename valP,
138  typename valW>
139  TString UserObject(const char* histClass,
140  const char* name,
141  const char* title,
142  const TVectorD* const binsX,
143  valX valTypeX,
144  const TVectorD* const binsY,
145  valY valTypeY,
146  const TVectorD* const binsZ,
147  valZ valTypeZ,
148  valP valTypeP,
149  valW valTypeW,
150  TString option);
151 
152  // 1D
153  template<typename valX, typename valW>
154  TString AddHistogram(const char* histClass,
155  const TVectorD* const binsX,
156  valX valTypeX,
157  valW valTypeW) {
158  return UserObject(histClass,
159  "",
160  "",
161  binsX,
162  valTypeX,
163  0x0,
164  (UInt_t) kNone,
165  0x0,
166  (UInt_t) kNone,
167  (UInt_t) kNoProfile,
168  valTypeW,
169  "");
170  }
171 
172  template<typename valX>
173  TString AddHistogram(const char* histClass,
174  const TVectorD* const binsX,
175  valX valTypeX) {
176  return AddHistogram(histClass, binsX, valTypeX, (UInt_t) kNoWeights);
177  }
178 
179  template<typename valX, typename valP, typename valW>
180  TString AddProfile(const char* histClass,
181  const TVectorD* const binsX,
182  valX valTypeX,
183  valP valTypeP,
184  TString option,
185  valW valTypeW) {
186  return UserObject(histClass,
187  "",
188  "",
189  binsX,
190  valTypeX,
191  0x0,
192  valTypeP,
193  0x0,
194  (UInt_t) kNone,
195  valTypeP,
196  valTypeW,
197  option);
198  }
199 
200  template<typename valX, typename valP>
201  TString AddProfile(const char* histClass,
202  const TVectorD* const binsX,
203  valX valTypeX,
204  valP valTypeP,
205  TString option) {
206  return AddProfile(
207  histClass, binsX, valTypeX, valTypeP, option, (UInt_t) kNoWeights);
208  }
209 
210  // 2D
211  template<typename valX, typename valY, typename valW>
212  TString AddHistogram(const char* histClass,
213  const TVectorD* const binsX,
214  valX valTypeX,
215  const TVectorD* const binsY,
216  valY valTypeY,
217  valW valTypeW) {
218  return UserObject(histClass,
219  "",
220  "",
221  binsX,
222  valTypeX,
223  binsY,
224  valTypeY,
225  0x0,
226  (UInt_t) kNone,
227  (UInt_t) kNoProfile,
228  valTypeW,
229  "");
230  }
231 
232  template<typename valX, typename valY>
233  TString AddHistogram(const char* histClass,
234  const TVectorD* const binsX,
235  valX valTypeX,
236  const TVectorD* const binsY,
237  valY valTypeY) {
238  return AddHistogram(
239  histClass, binsX, valTypeX, binsY, valTypeY, (UInt_t) kNoWeights);
240  }
241 
242  template<typename valX, typename valY, typename valP, typename valW>
243  TString AddProfile(const char* histClass,
244  const TVectorD* const binsX,
245  valX valTypeX,
246  const TVectorD* const binsY,
247  valY valTypeY,
248  valP valTypeP,
249  TString option,
250  valW valTypeW) {
251  return UserObject(histClass,
252  "",
253  "",
254  binsX,
255  valTypeX,
256  binsY,
257  valTypeY,
258  0x0,
259  valTypeP,
260  valTypeP,
261  valTypeW,
262  option);
263  }
264 
265  template<typename valX, typename valY, typename valP>
266  TString AddProfile(const char* histClass,
267  const TVectorD* const binsX,
268  valX valTypeX,
269  const TVectorD* const binsY,
270  valY valTypeY,
271  valP valTypeP,
272  TString option) {
273  return AddProfile(histClass,
274  binsX,
275  valTypeX,
276  binsY,
277  valTypeY,
278  valTypeP,
279  option,
280  (UInt_t) kNoWeights);
281  }
282 
283  // 3D
284  template<typename valX, typename valY, typename valZ, typename valW>
285  TString AddHistogram(const char* histClass,
286  const TVectorD* const binsX,
287  valX valTypeX,
288  const TVectorD* const binsY,
289  valY valTypeY,
290  const TVectorD* const binsZ,
291  valZ valTypeZ,
292  valW valTypeW) {
293  return UserObject(histClass,
294  "",
295  "",
296  binsX,
297  valTypeX,
298  binsY,
299  valTypeY,
300  binsZ,
301  valTypeZ,
302  (UInt_t) kNoProfile,
303  valTypeW,
304  "");
305  }
306 
307  template<typename valX, typename valY, typename valZ>
308  TString AddHistogram(const char* histClass,
309  const TVectorD* const binsX,
310  valX valTypeX,
311  const TVectorD* const binsY,
312  valY valTypeY,
313  const TVectorD* const binsZ,
314  valZ valTypeZ) {
315  return AddHistogram(histClass,
316  binsX,
317  valTypeX,
318  binsY,
319  valTypeY,
320  binsZ,
321  valTypeZ,
322  (UInt_t) kNoWeights);
323  }
324 
325  //profs
326  template<typename valX,
327  typename valY,
328  typename valZ,
329  typename valP,
330  typename valW>
331  TString AddProfile(const char* histClass,
332  const TVectorD* const binsX,
333  valX valTypeX,
334  const TVectorD* const binsY,
335  valY valTypeY,
336  const TVectorD* const binsZ,
337  valZ valTypeZ,
338  valP valTypeP,
339  TString option,
340  valW valTypeW) {
341  return UserObject(histClass,
342  "",
343  "",
344  binsX,
345  valTypeX,
346  binsY,
347  valTypeY,
348  binsZ,
349  valTypeZ,
350  valTypeP,
351  valTypeW,
352  option);
353  }
354 
355  template<typename valX, typename valY, typename valZ, typename valP>
356  TString AddProfile(const char* histClass,
357  const TVectorD* const binsX,
358  valX valTypeX,
359  const TVectorD* const binsY,
360  valY valTypeY,
361  const TVectorD* const binsZ,
362  valZ valTypeZ,
363  valP valTypeP,
364  TString option) {
365  return AddProfile(histClass,
366  binsX,
367  valTypeX,
368  binsY,
369  valTypeY,
370  binsZ,
371  valTypeZ,
372  valTypeP,
373  option,
374  (UInt_t) kNoWeights);
375  }
376 
377  // functions to fill objects
378  // void FillClass(const char* histClass, const Double_t *values);
379  void FillClass(TString histClass, const Double_t* values);
380  static void FillValues(TObject* obj, const Double_t* values);
381  static void FillValues(TH1* obj, const Double_t* values);
382  static void FillValues(THnBase* obj, const Double_t* values);
383 
384  // functions to get and draw histograms
385  void ReadFromFile(const char* file = "histos.root",
386  const char* task = "",
387  const char* config = "");
388  void DumpToFile(const char* file = "histos.root");
389  void SetList(TList* const list) { fList = list; }
390  TList* GetList() const { return fList; }
391  Bool_t SetCutClass(const char* cutClass);
392  Bool_t HasHistClass(TString histClass) const {
393  return fHistoList.FindObject(histClass.Data());
394  }
395  void SetHistogramList(THashList& list, Bool_t setOwner = kTRUE);
396  void ResetHistogramList() { fHistoList.Clear(); }
397  const THashList* GetHistogramList() const { return &fHistoList; }
398 
399  TObject* GetHist(const char* histClass, const char* name) const;
400  TH1* GetHistogram(const char* histClass, const char* name) const;
401  TObject*
402  GetHist(const char* cutClass, const char* histClass, const char* name) const;
403  TH1* GetHistogram(const char* cutClass,
404  const char* histClass,
405  const char* name) const;
406 
407 
408  PairAnalysisMetaData* GetMetaData() const { return fMetaData; }
409 
410  virtual void Print(const Option_t* option = "") const;
411  virtual void Draw(const Option_t* option = "");
412  virtual TObjArray* DrawSame(TString histName,
413  TString option = "leg can",
414  TString histClassDenom = "",
415  THashList* listDenom = 0x0);
416  virtual TObjArray* DrawTaskSame(TString histName,
417  TString opt = "leg can",
418  TString histClassDenom = "",
419  TString taskDenom = "");
420 
421 
422 protected:
423  THashList fHistoList; //-> list of histograms
424 
425 
426  //private:
427 
428  TFormula* GetFormula(const char* name, const char* formula);
429  TH1* GetTHist(const char* histClass,
430  const char* name,
431  const char* title,
432  const TVectorD* const binsX,
433  const TVectorD* const binsY,
434  const TVectorD* const binsZ);
435  TH1* GetTProf(const char* histClass,
436  const char* name,
437  const char* title,
438  const TVectorD* const binsX,
439  const TVectorD* const binsY,
440  const TVectorD* const binsZ,
441  TString option = "i");
442 
443  void FillVarArray(TObject* obj, UInt_t* valType);
444 
445  PairAnalysisMetaData* fMetaData;
446  // THashList fHistoList; //-> list of histograms
447  TList* fList;
448  TBits* fUsedVars; // list of used variables
449 
450  TString* fReservedWords;
451  void UserHistogramReservedWords(const char* histClass, const TObject* hist);
452  void FillClass(THashTable* classTable, Int_t nValues, Double_t* values);
453 
454  void PrintPDF(Option_t* opt);
455  void PrintStructure() const;
456 
457  Bool_t IsHistogramOk(const char* classTable, const char* name);
458  Eprecision fPrecision;
459 
460  PairAnalysisHistos(const PairAnalysisHistos& hist);
461  PairAnalysisHistos& operator=(const PairAnalysisHistos& hist);
462 
463  ClassDef(PairAnalysisHistos, 3) // Histogram management
464 };
465 
466 template<typename valX,
467  typename valY,
468  typename valZ,
469  typename valP,
470  typename valW>
471 TString PairAnalysisHistos::UserObject(const char* histClass,
472  const char* name,
473  const char* title,
474  const TVectorD* const binsX,
475  valX valTypeX,
476  const TVectorD* const binsY,
477  valY valTypeY,
478  const TVectorD* const binsZ,
479  valZ valTypeZ,
480  valP valTypeP,
481  valW valTypeW,
482  TString option) {
483  //
484  // main function to setup the histogram with given variables, binning and dimensions
485  //
486  TH1* hist = 0x0;
487  TString err = "err";
488  //profile or histogram
489  if (typeid(valTypeP) == typeid(UInt_t) && (uintptr_t) valTypeP == kNoProfile)
490  hist = GetTHist(histClass, name, title, binsX, binsY, binsZ);
491  else
492  hist = GetTProf(histClass, name, title, binsX, binsY, binsZ, option);
493  if (!hist) {
494  delete binsX;
495  return err;
496  }
497 
498  // add formulas to the histograms list of functions
499  // and store variales in uniqueIDs
500  UInt_t valType[20] = {0};
501  TString func = "";
502  func += valTypeX;
503  if (!func.Atoi())
504  hist->GetListOfFunctions()->Add(GetFormula("xFormula", func));
505  else
506  valType[0] = func.Atoi();
507 
508  func = "";
509  func += valTypeY;
510  if (!func.Atoi())
511  hist->GetListOfFunctions()->Add(GetFormula("yFormula", func));
512  else
513  valType[1] = func.Atoi();
514 
515  func = "";
516  func += valTypeZ;
517  if (!func.Atoi())
518  hist->GetListOfFunctions()->Add(GetFormula("zFormula", func));
519  else
520  valType[2] = func.Atoi();
521 
522  func = "";
523  func += valTypeP;
524  if (!func.Atoi())
525  hist->GetListOfFunctions()->Add(GetFormula("pFormula", func));
526  else
527  valType[3] = func.Atoi();
528 
529  TString func2 = "";
530  func2 += valTypeX;
531  func = "";
532  func += valTypeW;
533  if (!func.Atoi())
534  hist->GetListOfFunctions()->Add(GetFormula("wFormula", func));
535  else if (func2.Atoi() != kNoWeights) {
536  hist->SetUniqueID(func.Atoi()); // store weighting variable
537  fUsedVars->SetBitNumber(func.Atoi(), kTRUE);
538  }
539 
540  // store variables and their usage
541  StoreVariables(hist, valType);
542  for (Int_t i = 0; i < 4; i++)
543  fUsedVars->SetBitNumber(valType[i], kTRUE);
544 
545  // adapt the name and title of the histogram in case they are empty
546  AdaptNameTitle(hist, histClass);
547 
548  // save histname
549  TString key = hist->GetName();
550  // set pdg code labels
551  /*
552  if(hist->GetDimension()==1) {
553  func=""; func+=valTypeX;
554  if(func.Contains("PdgCode") ||
555  func.Atoi()==PairAnalysisVarManager::kPdgCode ||
556  func.Atoi()==PairAnalysisVarManager::kPdgCodeMother ||
557  func.Atoi()==PairAnalysisVarManager::kPdgCodeGrandMother ||
558  ) PairAnalysisHelper::SetPDGBinLabels(hist);
559  }
560  */
561 
562  Bool_t isReserved = fReservedWords->Contains(histClass);
563  if (func2.Atoi() && func2.Atoi() == kNoAutoFill)
564  hist->SetUniqueID(func2.Atoi());
565  if (isReserved)
566  UserHistogramReservedWords(histClass, hist);
567  else
568  UserHistogram(histClass, hist);
569 
570  delete binsX;
571  delete binsY;
572  delete binsZ;
573 
574  return key;
575 }
576 
577 #endif
PairAnalysisHelper.h
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
PairAnalysisHn::PairAnalysisHn
PairAnalysisHn(const char *name, const char *title, Int_t dim, const Int_t *nbins, const Double_t *xmin=0, const Double_t *xmax=0, Int_t chunksize=1024 *16)
Definition: PairAnalysisHistos.h:54
PairAnalysisHn::fFunctions
TList * fFunctions
Definition: PairAnalysisHistos.h:80
PairAnalysisHn
Definition: PairAnalysisHistos.h:50
PairAnalysisHn::PairAnalysisHn
PairAnalysisHn()
Definition: PairAnalysisHistos.h:53
PairAnalysisHelper::GetFormula
TFormula * GetFormula(const char *name, const char *formula)
Definition: PairAnalysisHelper.cxx:330
PairAnalysisHn::PairAnalysisHn
PairAnalysisHn(const PairAnalysisHn &hist)
PairAnalysisVarManager.h
PairAnalysisHn::GetListOfFunctions
TList * GetListOfFunctions() const
Definition: PairAnalysisHistos.h:52
task
@ task
Definition: CbmMvdSensorPlugin.h:22
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
PairAnalysisHn::~PairAnalysisHn
~PairAnalysisHn()
Definition: PairAnalysisHistos.h:64
PairAnalysisHn::operator=
PairAnalysisHn & operator=(const PairAnalysisHn &hist)
PairAnalysisMetaData.h
PairAnalysisMetaData
Definition: PairAnalysisMetaData.h:27