HighLAND
CategoryClasses.hxx
1 #ifndef CategoryClasses_h
2 #define CategoryClasses_h
3 
4 #include <map>
5 #include <vector>
6 #include <stdio.h>
7 #include <iostream>
8 #include <TObject.h>
9 
10 /// A TrackTypeDefinition is one of the possiple options for a
11 /// TrackCategoryDefinition. The "particle" category, for example, has types
12 /// "muon", "electron" etc.
13 ///
14 /// This class is very simple. See TrackCategoryDefinition for more details on
15 /// categories, and their use in drawing stacked histograms.
16 class TrackTypeDefinition: public TObject {
17 
18  public:
19 
21  virtual ~TrackTypeDefinition() {}
22 
23  /// The name of this type ("muon", "electron", ...). It will be displayed in the legend.
24  std::string _name;
25 
26  /// The color to be displayed for tracks of this type.
27  int _color;
28 
29  /// The order in which it should appear when plotting.
30  int _order;
31 
32  /// The unique code for this type ("muon==13", ...).
33  int _code;
34 
35  /// Is this type enabled?
36  bool _enabled;
37 
38  ClassDef(TrackTypeDefinition, 1);
39 };
40 
41 /// A TrackCategoryDefinition allows the plotting of stacked histograms in the
42 /// DrawingTools. For example, a histogram may be broken down by the true
43 /// particle of the selected track. This "particle" category has types such as
44 /// "electron", "muon" and so on. The "particle" variable in the analysis
45 /// micro-tree would then be filled with the appropriate code.
46 ///
47 /// Categories are managed using the CategoryManager, and are saved to the
48 /// "config" tree of the output file. This means that custom categories can be
49 /// defined by the analyser, and automatically used in the DrawingTools. See
50 /// CategoryManager::AddTrackCategory() for how to do this.
51 class TrackCategoryDefinition: public TObject {
52 
53  public:
54 
55  /// Create a new track category. Setting "multi" to true means that several
56  /// types can coexist.
57  TrackCategoryDefinition(bool multi = false) {
58  _isMultiType = multi;
59  }
60 
61  virtual ~TrackCategoryDefinition() {}
62 
63  /// Number of types defined for this category.
64  unsigned int GetNTypes() {
65  return _types.size();
66  }
67 
68  /// Get the types defined for this category.
69  std::vector<TrackTypeDefinition>& GetCategoryTypes() {
70  return _types;
71  }
72 
73  /// Add a new type to this category.
75  _types.push_back(type);
76  }
77 
78  /// Is this a multi-type category ? (Can several types coexist?)
79  bool IsMultiType() {
80  return _isMultiType;
81  }
82 
83  /// Get the code for the actual track in this category.
84  int GetCode() {
85  return _code;
86  }
87 
88  /// Check if the actual track is of this type
89  bool CheckCategoryType(int index) {
90  return _typesOK[index];
91  }
92 
93  /// Set the code for the actual track. Use defaultcode if code isn't
94  /// defined for this category.
95  void SetCode(int code, int defaultcode = -999) {
96  bool ok = false;
97 
98  for (std::vector<TrackTypeDefinition>::iterator it = _types.begin(); it != _types.end(); it++) {
99  if (it->_code == code) {
100  ok = true;
101  break;
102  }
103  }
104 
105  if (!ok) {
106  code = defaultcode;
107  }
108 
109  _code = code;
110  }
111 
112  /// Set the type for the actual track.
113  void SetCategoryType(int index, bool ok) {
114  _typesOK[index] = ok;
115  }
116 
117  void Reset(){_types.clear(); _isMultiType=false;}
118 
119 
120  // Get an array with all type names for this category
121  std::string* GetNames(std::string names[]);
122 
123  // Get an array with all colors for this category
124  Int_t* GetColors(Int_t colors[]);
125 
126  // Get an array with all codes for this category
127  Int_t* GetCodes(Int_t codes[]);
128 
129 
130  protected:
131 
132  /// The types for the actual track.
133  std::vector<bool> _typesOK; //!
134 
135  /// The code for the actual track.
136  int _code; //!
137 
138  public:
139 
140  /// The name of this category (e.g. "particle").
141  std::string _name;
142 
143  /// Whether this is this a multi-type category (can several types coexist?).
145 
146  /// The types defined for this category.
147  std::vector<TrackTypeDefinition> _types;
148 
149  ClassDef(TrackCategoryDefinition, 1);
150 };
151 
152 //typedef TrackTypeDefinition CategoryTypeDefinition;
153 //typedef TrackCategoryDefinition CategoryDefinition ;
154 
155 #endif
bool _enabled
Is this type enabled?
bool _isMultiType
Whether this is this a multi-type category (can several types coexist?).
void SetCategoryType(int index, bool ok)
Set the type for the actual track.
bool IsMultiType()
Is this a multi-type category ? (Can several types coexist?)
int _code
The unique code for this type ("muon==13", ...).
void AddType(TrackTypeDefinition &type)
Add a new type to this category.
int _order
The order in which it should appear when plotting.
TrackCategoryDefinition(bool multi=false)
int _color
The color to be displayed for tracks of this type.
std::vector< TrackTypeDefinition > _types
The types defined for this category.
int GetCode()
Get the code for the actual track in this category.
std::string _name
The name of this type ("muon", "electron", ...). It will be displayed in the legend.
void SetCode(int code, int defaultcode=-999)
unsigned int GetNTypes()
Number of types defined for this category.
std::vector< TrackTypeDefinition > & GetCategoryTypes()
Get the types defined for this category.
int _code
The code for the actual track.
std::vector< bool > _typesOK
The types for the actual track.
std::string _name
The name of this category (e.g. "particle").
bool CheckCategoryType(int index)
Check if the actual track is of this type.