HighLAND
Public Member Functions | Protected Attributes | List of all members
CategoryManager Class Reference
Inheritance diagram for CategoryManager:
HLClonesArray

Public Member Functions

 CategoryManager ()
 Private constructor as this is a singleton.
 
void ResetCurrentCategories ()
 Reset the properties of the current track.
 
void AddCategory (const std::string &name, int ntypes, std::string *names, int *codes, int *colors, bool multi=false, bool noWarning=false, bool addNOTRUTH=true, bool addSAND=true)
 
void CopyCategory (const std::string &categ_name, const std::string &categ_name2)
 Copy an existing Category into another with a different name.
 
bool HasCategory (const std::string &categ)
 Has this category been added?
 
void ReadCategories (const std::string &file)
 Build the categories from a root file.
 
std::map< std::string, TrackCategoryDefinition * > & GetCategories ()
 Get the map of track categories.
 
void DumpCategories ()
 Dump the map of track categories.
 
void DumpCategory (const std::string &categ)
 Dump the options stored for the given category.
 
TrackCategoryDefinitionGetCategory (const std::string &categ)
 Get a specific category.
 
std::vector< TrackTypeDefinition > & GetCategoryTypes (const std::string &categ)
 Get the vector of track types in a given category.
 
void SetCode (const std::string &categ, int code, int defaultcode=0)
 
void SetCategoryType (const std::string &categ, int type, bool ok)
 
int GetCode (const std::string &categ)
 Get the actual code for this category.
 
bool CheckCategoryType (const std::string &categ, int index)
 
bool IsReady () const
 Whether the categories are ready.
 
void SetReady (bool ok)
 Set that the categories are ready.
 
- Public Member Functions inherited from HLClonesArray
 HLClonesArray (const std::string &tree_name, const std::string &tcarray_name, const std::string &class_name, const UInt_t size)
 
void ReadClonesArray (const std::string &file)
 
void WriteClonesArray (TTree &tree)
 
Int_t & GetNObjects ()
 Return the number of steps that have been added.
 
TClonesArray * GetClonesArray ()
 
const std::string & GetClonesArrayName () const
 Return the name of the TClonesArray.
 
const std::string & GetTreeName () const
 Return the name of the tree.
 

Protected Attributes

std::map< std::string, TrackCategoryDefinition * > _track_category_map
 The internal map of categories and the names they were registered with.
 
bool _ready
 Whether the categories are ready.
 
- Protected Attributes inherited from HLClonesArray
TChain * _chain
 TChain used to read the "config" tree from the output file.
 
Int_t _NObjects
 The number of steps that were added.
 
TClonesArray * _objects
 
std::string _tcArrayName
 Name of the TClonesArray in the tree.
 
std::string _treeName
 Name of the Tree.
 
std::string _fileName
 Name of the last file read.
 

Detailed Description

Definition at line 54 of file CategoryManager.hxx.

Member Function Documentation

§ AddCategory()

void CategoryManager::AddCategory ( const std::string &  name,
int  ntypes,
std::string *  names,
int *  codes,
int *  colors,
bool  multi = false,
bool  noWarning = false,
bool  addNOTRUTH = true,
bool  addSAND = true 
)

Add a new track category. This will be automatically saved in the "config" tree, so can be used in the DrawingTools.

name: The name of this category (for example, "particle"). ntypes: The number of types this category permits. names: The names of the types this category permits (e.g. "muon"...). codes: The codes that associate a track with a given type. See SetCode(). colors: The colors to be used when drawing the stacked histogram. multi: Whether the category should allow multiple types to coexist. noWarning: avoid warning when replacing properties, used for drawing with % on the legend (with PUR option) addNOTRUTH: atutomatically add the NOTRUTH type addSAND: atutomatically add the SAND muon type The array variables should all be ntypes in length.

Definition at line 21 of file CategoryManager.cxx.

21  {
22 //********************************************************************
23 
24  // Fill this track category definition
25 
27  if (HasCategory(categ_name)){
28  if ( ! noWarning)
29  std::cerr << "WARNING: category '" << categ_name << "' already exists !!! Replacing properties..." << std::endl;
30  categ = _track_category_map[categ_name];
31  categ->Reset();
32  }
33  else{
34  categ = new((*_objects)[_NObjects++]) TrackCategoryDefinition(multi);
35  categ->_name = categ_name;
36  // Add it to the map of categories
37  _track_category_map[categ_name] = categ;
38  }
39 
40  for (int i=0;i<ntypes;i++) {
41  if ( ! noWarning && addSAND && codes[i]==CATSAND) {
42  std::cerr << "ERROR in CategoryManager::AddCategory: for category '" << categ_name
43  << "' user type " << i << " '" << names[i] << "' has same code " << codes[i]
44  << " as the automatic SAND muon type. Please use a different code !!!" << std::endl;
45  }
46  if ( ! noWarning && addNOTRUTH && codes[i]==CATNOTRUTH) {
47  std::cerr << "ERROR in CategoryManager::AddCategory: for category '" << categ_name
48  << "' user type " << i << " '" << names[i] << "' has same code " << codes[i]
49  << " as the automatic NO TRUTH type. Please use a different code !!!" << std::endl;
50  }
51 
53  type._name = names[i];
54  type._code = codes[i];
55  type._color = colors[i];
56  type._order = i;
57  type._enabled=true;
58  categ->AddType(type);
59  }
60 
61  // add "notruth" and "sand #mu" type to all categories unless specified otherwise with the input arguments
62 
63  if (addNOTRUTH){
64  // first no truth (since often sand has no truth)
66  type._name = NAMENOTRUTH;
67  type._code = CATNOTRUTH;
68  type._color = COLNOTRUTH;
69  type._order = categ->GetNTypes();
70  type._enabled = true;
71  categ->AddType(type);
72  }
73 
74  if (addSAND){
75  // sand as last type
76  TrackTypeDefinition typeSand;
77  typeSand._name = NAMESAND;
78  typeSand._code = CATSAND;
79  typeSand._color = COLSAND;
80  typeSand._order = categ->GetNTypes();
81  typeSand._enabled = true;
82  categ->AddType(typeSand);
83  }
84 }
bool _enabled
Is this type enabled?
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.
int _color
The color to be displayed for tracks of this type.
Int_t _NObjects
The number of steps that were added.
std::string _name
The name of this type ("muon", "electron", ...). It will be displayed in the legend.
unsigned int GetNTypes()
Number of types defined for this category.
bool HasCategory(const std::string &categ)
Has this category been added?
std::map< std::string, TrackCategoryDefinition * > _track_category_map
The internal map of categories and the names they were registered with.
std::string _name
The name of this category (e.g. "particle").

§ CheckCategoryType()

bool CategoryManager::CheckCategoryType ( const std::string &  categ,
int  index 
)

Check is the specified type is true for a given category (for multitype categories only)

Definition at line 212 of file CategoryManager.cxx.

212  {
213 //********************************************************************
214 
215  if (!HasCategory(categ)) return -1;
216 
217  if (GetCategory(categ).IsMultiType())
218  return GetCategory(categ).CheckCategoryType(index);
219  else{
220  std::cout << "Category '" << categ << "' is a single-type category" << std::endl;
221  return false;
222  }
223 }
TrackCategoryDefinition & GetCategory(const std::string &categ)
Get a specific category.
bool HasCategory(const std::string &categ)
Has this category been added?
bool CheckCategoryType(int index)
Check if the actual track is of this type.

§ SetCategoryType()

void CategoryManager::SetCategoryType ( const std::string &  categ,
int  type,
bool  ok 
)
inline

A category can fulfill multiple types. Set the different bits. For multitype categories only.

Definition at line 124 of file CategoryManager.hxx.

124  {
125  if (HasCategory(categ)) {
126  GetCategory(categ).SetCategoryType(type, ok);
127  }
128  }
void SetCategoryType(int index, bool ok)
Set the type for the actual track.
TrackCategoryDefinition & GetCategory(const std::string &categ)
Get a specific category.
bool HasCategory(const std::string &categ)
Has this category been added?

§ SetCode()

void CategoryManager::SetCode ( const std::string &  categ,
int  code,
int  defaultcode = 0 
)
inline

Set the actual code for this category. If the specified code isn't defined for the category, defaultcode is used instead.

Definition at line 114 of file CategoryManager.hxx.

114  {
115  if (HasCategory(categ)) {
116  GetCategory(categ).SetCode(code, defaultcode);
117  } else {
118  std::cout << "Code not set: category '" << categ << "' not found !!!" << std::endl;
119  }
120  }
TrackCategoryDefinition & GetCategory(const std::string &categ)
Get a specific category.
void SetCode(int code, int defaultcode=-999)
bool HasCategory(const std::string &categ)
Has this category been added?

The documentation for this class was generated from the following files: