]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/base/AliCounterCollection.h
Added two Get methods to get counters in histograms without drawing them (Philippe P.)
[u/mrichter/AliRoot.git] / PWG3 / base / AliCounterCollection.h
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
13 class TString;
14 class TObjArray;
15 class THnSparse;
16 class THashList;
17 class TArrayI;
18 class TH1D;
19 class TH2D;
20 class TCollection;
21
22 class AliCounterCollection : public TNamed {
23 public:
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
35   void Init(Bool_t weightedCounters = kFALSE);
36   
37   // return the list of key words for the given rubric
38   TString GetKeyWords(TString rubric) const;
39   
40   // Add "value" to the counter referenced by "externalKey"
41   void Count(TString externalKey, Int_t value = 1);
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 = "");
46   // Get counters of the rubric "rubric1" for the given "selection"
47   TH1D* Get(TString rubric1, TString selections);
48   // Get counters of the "rubric1" vs "rubric2" for the given "selection"
49   TH2D* Get(TString rubric1, TString rubric2, TString selections);
50   
51   // Print every individual counters if opt=="", else call "Print(TString rubrics=opt, TString selections="")"
52   virtual void Print(const Option_t* opt = "") const;
53   // Print the full list of key words
54   void PrintKeyWords() const;
55   // Print value of selected counter
56   void PrintValue(TString selections);
57   // Print desired rubrics for the given selection
58   void Print(TString rubrics, TString selections);
59   // Print the overall statistics for the given selection (result is integrated over not specified rubrics)
60   void PrintSum(TString selections = "");
61   
62   /// Overload TObject::Draw(Option_t*): Call "Draw(TString rubric1=opt, TString selections="")"
63   virtual void Draw(Option_t* opt = "") {Draw(opt, "");}
64   // Draw counters of the rubric "rubric1" for the given "selection"
65   TH1D* Draw(TString rubric1, TString selections);
66   // Draw counters of the "rubric1" vs "rubric2" for the given "selection"
67   TH2D* Draw(TString rubric1, TString rubric2, TString selections);
68   
69   // Add the given AliCounterCollections to this
70   void Add(const AliCounterCollection* counter);
71   
72   // Merge this with a list of AliCounterCollections
73   Long64_t Merge(TCollection* list);
74   
75   // Sort rubrics defined without a list of authorized key words or all rubrics if opt=="all"
76   void Sort(Option_t* opt = "", Bool_t asInt = kFALSE);
77   /// Sort only that rubric. If asInt=kTRUE, key words are ordered as interger instead of alphabetically
78   void SortRubric(TString rubric, Bool_t asInt = kFALSE);
79   
80 private:
81   
82   /// Not implemented
83   AliCounterCollection(const AliCounterCollection& rhs);
84   /// Not implemented
85   AliCounterCollection& operator = (const AliCounterCollection& rhs);
86   
87   // return the number of labels in that rubric
88   Int_t GetNActiveBins(Int_t dim);
89   // return kTRUE if that rubric contains the keyWord "ANY"
90   Bool_t ContainsAny(Int_t dim);
91     
92   // Return the corresponding bins ordered by rubric or 0x0 if externalKey is not valid
93   const Int_t* FindBins(const TString& externalKey, Bool_t allocate, Int_t& nEmptySlots);
94   // Return the dimension corresponding to that rubric (or -1)
95   Int_t FindDim(const TString& rubricName) const;
96   // Return the bin number corresponding to that key word (or -1)
97   Int_t FindBin(Int_t dim, const TString& keyWord, Bool_t allocate);
98   
99   // Tag the selected keywords in each rubric (-1=subtract; 0=discard; 1=add)
100   Short_t** DecodeSelection(const TString& selections, const TObjArray& displayedRubrics);
101   // Tag the selected keywords (separated by ',') in that rubric (-1=subtract; 0=discard; 1=add)
102   Bool_t Select(Bool_t include, const TString& rubric, const TString& keywords, Bool_t displayed, Short_t* selectBins[]);
103     
104   // Make sure all strings appear only once in this list
105   void CleanListOfStrings(TObjArray* list);
106   
107   // Add "value" to the counter referenced by "externalKey"
108   void CountAsDouble(TString externalKey, Double_t value);
109   
110   // Print the content of 1D histogram as a list
111   void PrintList(const TH1D* hist) const;
112   // Print the content of 2D histogram as an array
113   void PrintArray(const TH2D* hist) const;
114   // Print the content of nD histogram as a list of arrays
115   void PrintListOfArrays(const THnSparse* hist) const;
116   
117   // Return the number of characters of the longest label
118   Int_t GetMaxLabelSize(THashList* labels) const;
119   
120   // Return desired "data" for the given "selection" stored in a new histogram or 0x0
121   TObject* Projection(const TObjArray& data, const TString& selections);
122   
123   // Consistency check of the two counter collections
124   Int_t* CheckConsistency(const AliCounterCollection* c);
125   
126   // Sort labels (alphabetically or as integer) in each rubric flagged in "rubricsToSort"
127   void Sort(const Bool_t* rubricsToSort, Bool_t asInt);
128   /// Return a list (not owner) of labels sorted assuming they are integers
129   THashList* SortAsInt(const THashList* labels);
130   
131 private:
132   
133   THashList* fRubrics;        ///< list of rubrics with associated key words
134   TArrayI*   fRubricsSize;    ///< maximum number of key words in the corresponding rubric
135   THnSparse* fCounters;       ///< histogram of nRubrics dimensions used as n-dimensional counter
136   Bool_t fWeightedCounters;   ///< use THnSparseF instead of THnSparseI
137   
138   ClassDef(AliCounterCollection, 2); // collection of mergeable counters
139 };
140
141 #endif
142