New option (in the init()) to produce weighted counters, which support also float...
[u/mrichter/AliRoot.git] / PWG3 / base / AliCounterCollection.h
CommitLineData
94ef1a28 1#ifndef ALICOUNTERCOLLECTION_H
2#define ALICOUNTERCOLLECTION_H
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
5
6/// \ingroup PWG3muon
7/// \class AliCounterCollection
8/// \brief generic class to handle a collection of counters
9// Author: Philippe Pillot
10
11#include <TNamed.h>
12
13class TString;
14class TObjArray;
15class THnSparse;
16class THashList;
17class TArrayI;
18class TH1D;
19class TH2D;
20class TCollection;
21
22class AliCounterCollection : public TNamed {
23public:
24
25 AliCounterCollection(const char* name = "counters");
26 virtual ~AliCounterCollection();
27
28 virtual void Clear(Option_t* = "");
29
30 // Add a new rubric with the complete list of related key words separated by "/"
31 void AddRubric(TString name, TString listOfKeyWords);
32 // Add a new rubric containing at maximum maxNKeyWords key words
33 void AddRubric(TString name, Int_t maxNKeyWords);
34 // Initialize the internal counters from the added rubrics
d810835e 35 void Init(Bool_t weightedCounters = kFALSE);
94ef1a28 36
d649ab79 37 // return the list of key words for the given rubric
38 TString GetKeyWords(TString rubric) const;
39
94ef1a28 40 // Add "value" to the counter referenced by "externalKey"
41 void Count(TString externalKey, Int_t value = 1);
d810835e 42 void Count(TString externalKey, Double_t value);
43
44 // Get the overall statistics for the given selection (result is integrated over not specified rubrics)
45 Double_t GetSum(TString selections = "");
94ef1a28 46
47 // Print every individual counters if opt=="", else call "Print(TString rubrics=opt, TString selections="")"
48 virtual void Print(const Option_t* opt = "") const;
49 // Print the full list of key words
50 void PrintKeyWords() const;
51 // Print value of selected counter
52 void PrintValue(TString selections);
53 // Print desired rubrics for the given selection
54 void Print(TString rubrics, TString selections);
6f5626c7 55 // Print the overall statistics for the given selection (result is integrated over not specified rubrics)
56 void PrintSum(TString selections = "");
94ef1a28 57
58 /// Overload TObject::Draw(Option_t*): Call "Draw(TString rubric1=opt, TString selections="")"
59 virtual void Draw(Option_t* opt = "") {Draw(opt, "");}
60 // Draw counters of the rubric "rubric1" for the given "selection"
61 TH1D* Draw(TString rubric1, TString selections);
62 // Draw counters of the "rubric1" vs "rubric2" for the given "selection"
63 TH2D* Draw(TString rubric1, TString rubric2, TString selections);
64
65 // Add the given AliCounterCollections to this
66 void Add(const AliCounterCollection* counter);
67
68 // Merge this with a list of AliCounterCollections
69 Long64_t Merge(TCollection* list);
70
71 // Sort rubrics defined without a list of authorized key words or all rubrics if opt=="all"
72 void Sort(Option_t* opt = "", Bool_t asInt = kFALSE);
73 /// Sort only that rubric. If asInt=kTRUE, key words are ordered as interger instead of alphabetically
74 void SortRubric(TString rubric, Bool_t asInt = kFALSE);
75
76private:
77
78 /// Not implemented
79 AliCounterCollection(const AliCounterCollection& rhs);
80 /// Not implemented
81 AliCounterCollection& operator = (const AliCounterCollection& rhs);
82
6f5626c7 83 // return the number of labels in that rubric
84 Int_t GetNActiveBins(Int_t dim);
85 // return kTRUE if that rubric contains the keyWord "ANY"
86 Bool_t ContainsAny(Int_t dim);
87
94ef1a28 88 // Return the corresponding bins ordered by rubric or 0x0 if externalKey is not valid
89 const Int_t* FindBins(const TString& externalKey, Bool_t allocate, Int_t& nEmptySlots);
90 // Return the dimension corresponding to that rubric (or -1)
91 Int_t FindDim(const TString& rubricName) const;
92 // Return the bin number corresponding to that key word (or -1)
93 Int_t FindBin(Int_t dim, const TString& keyWord, Bool_t allocate);
94
6f5626c7 95 // Tag the selected keywords in each rubric (-1=subtract; 0=discard; 1=add)
96 Short_t** DecodeSelection(const TString& selections, const TObjArray& displayedRubrics);
97 // Tag the selected keywords (separated by ',') in that rubric (-1=subtract; 0=discard; 1=add)
98 Bool_t Select(Bool_t include, const TString& rubric, const TString& keywords, Bool_t displayed, Short_t* selectBins[]);
99
94ef1a28 100 // Make sure all strings appear only once in this list
101 void CleanListOfStrings(TObjArray* list);
102
d810835e 103 // Add "value" to the counter referenced by "externalKey"
104 void CountAsDouble(TString externalKey, Double_t value);
105
94ef1a28 106 // Print the content of 1D histogram as a list
107 void PrintList(const TH1D* hist) const;
108 // Print the content of 2D histogram as an array
109 void PrintArray(const TH2D* hist) const;
110 // Print the content of nD histogram as a list of arrays
111 void PrintListOfArrays(const THnSparse* hist) const;
112
113 // Return the number of characters of the longest label
114 Int_t GetMaxLabelSize(THashList* labels) const;
115
116 // Return desired "data" for the given "selection" stored in a new histogram or 0x0
117 TObject* Projection(const TObjArray& data, const TString& selections);
118
119 // Consistency check of the two counter collections
120 Int_t* CheckConsistency(const AliCounterCollection* c);
121
122 // Sort labels (alphabetically or as integer) in each rubric flagged in "rubricsToSort"
123 void Sort(const Bool_t* rubricsToSort, Bool_t asInt);
124 /// Return a list (not owner) of labels sorted assuming they are integers
125 THashList* SortAsInt(const THashList* labels);
126
127private:
128
129 THashList* fRubrics; ///< list of rubrics with associated key words
130 TArrayI* fRubricsSize; ///< maximum number of key words in the corresponding rubric
131 THnSparse* fCounters; ///< histogram of nRubrics dimensions used as n-dimensional counter
d810835e 132 Bool_t fWeightedCounters; ///< use THnSparseF instead of THnSparseI
94ef1a28 133
d810835e 134 ClassDef(AliCounterCollection, 2); // collection of mergeable counters
94ef1a28 135};
136
137#endif
138