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