ndmspc  v1.2.0-0.1.rc3
NGnNavigator.h
1 #ifndef Ndmspc_NGnNavigator_H
2 #define Ndmspc_NGnNavigator_H
3 #include <TNamed.h>
4 #include <Buttons.h>
5 #include <TList.h>
6 #include <cstddef>
7 #include <vector>
8 #include "NBinningDef.h"
9 #include "NGnTree.h"
10 namespace Ndmspc {
11 
22 class NGnNavigator : public TNamed {
23  public:
30  NGnNavigator(const char * name = "GnNavigator", const char * title = "Gn Navigator",
31  std::vector<std::string> objectTypes = {"TH1"});
32 
36  virtual ~NGnNavigator();
37 
47  NGnNavigator * Reshape(std::string binningName, std::vector<std::vector<int>> levels, size_t level = 0,
48  std::map<int, std::vector<int>> ranges = {}, std::map<int, std::vector<int>> rangesBase = {});
49 
60  NGnNavigator * Reshape(NBinningDef * binningDef, std::vector<std::vector<int>> levels, size_t level = 0,
61  std::map<int, std::vector<int>> ranges = {}, std::map<int, std::vector<int>> rangesBase = {},
62  NGnNavigator * parent = nullptr);
63 
71  void Export(const std::string & filename, std::vector<std::string> objectNames, const std::string & wsUrl = "",
72  int timeoutMs = 1000);
73 
80  void ExportToJson(json & j, NGnNavigator * obj, std::vector<std::string> objectNames);
81 
86  virtual void Print(Option_t * option = "") const override;
87 
92  virtual void Draw(Option_t * option = "") override;
93 
99  json GetInfoJson() const;
100 
115  virtual TList * DrawSpectra(std::string parameterName, std::vector<int> projIds, std::vector<double> minmax = {0.05},
116  const std::string& minmaxMode = "V", Option_t * option = "") const;
117 
133  virtual TList * DrawSpectraByName(std::string parameterName, std::vector<std::string> projAxes,
134  std::vector<double> minmax = {0.05}, const std::string& minmaxMode = "V", Option_t * option = "") const;
135 
149  virtual TList * DrawSpectraAll(std::string parameterName, std::vector<double> minmax = {0.05},
150  const std::string& minmaxMode = "V", Option_t * option = "") const;
151 
156  virtual void Paint(Option_t * option = "") override;
157 
164  Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
165 
172  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
173 
178  NGnTree * GetGnTree() const { return fGnTree; }
179 
184  void SetGnTree(NGnTree * tree) { fGnTree = tree; }
185 
190  std::vector<NGnNavigator *> GetChildren() const { return fChildren; }
191 
196  void SetChildrenSize(size_t n) { fChildren.resize(n); }
197 
203  NGnNavigator * GetChild(size_t index) const;
204 
214  NGnNavigator * GetChild(std::vector<std::vector<size_t>> coords) const;
215 
221  void SetChild(NGnNavigator * child, int index = -1);
222 
227  NGnNavigator * GetParent() const { return fParent; }
228 
237  NGnNavigator * GetRoot() const;
238 
243  void SetParent(NGnNavigator * parent) { fParent = parent; }
244 
249  std::map<std::string, std::vector<TObject *>> GetObjectContentMap() const { return fObjectContentMap; }
250 
256  void ResizeObjectContentMap(const std::string & name, size_t n) { fObjectContentMap[name].resize(n); };
257 
263  std::vector<TObject *> GetObjects(const std::string & name) const;
264 
271  TObject * GetObject(const std::string & name, int index = 0) const;
272 
279  void SetObject(const std::string & name, TObject * obj, int index = -1);
280 
285  void SetObjectTypes(const std::vector<std::string> & types) { fObjectTypes = types; }
286 
291  std::vector<std::string> GetObjectNames() const { return fObjectNames; }
292 
297  void SetObjectNames(const std::vector<std::string> & names) { fObjectNames = names; }
298 
303  std::map<std::string, std::vector<double>> GetParameterContentMap() const { return fParameterContentMap; }
304 
310  void ResizeParameterContentMap(const std::string & name, int n) { fParameterContentMap[name].resize(n); };
311 
317  std::vector<double> GetParameters(const std::string & name) const;
318 
325  double GetParameter(const std::string & name, int index = 0) const;
326 
333  void SetParameter(const std::string & name, double value, int index = -1);
334 
339  std::map<std::string, std::vector<double>> GetParameterErrorContentMap() const { return fParameterErrorContentMap; }
340 
346  void ResizeParameterErrorContentMap(const std::string & name, int n) { fParameterErrorContentMap[name].resize(n); };
347 
353  std::vector<double> GetParameterErrors(const std::string & name) const;
354 
361  double GetParameterError(const std::string & name, int index = 0) const;
362 
370  void SetParameterError(const std::string & name, double value, int index = -1);
375  std::vector<std::string> GetParameterNames() const { return fParameterNames; }
376 
381  void SetParameterNames(const std::vector<std::string> & names) { fParameterNames = names; }
382 
387  TH1 * GetProjection() const { return fProjection; }
388 
393  void SetProjection(TH1 * h) { fProjection = h; }
394 
399  size_t GetNLevels() const { return fNLevels; }
400 
405  void SetNLevels(size_t n) { fNLevels = n; }
406 
411  size_t GetLevel() const { return fLevel; }
412 
417  void SetLevel(size_t l) { fLevel = l; }
418 
423  std::vector<std::vector<int>> GetLevels() const { return fLevels; }
424 
429  void SetLevels(const std::vector<std::vector<int>> & levels) { fLevels = levels; }
430 
435  size_t GetNCells() const { return fNCells; }
436 
441  void SetNCells(size_t n) { fNCells = n; }
442 
447  size_t GetLastIndexSelected() const { return fLastIndexSelected; }
448 
453  void SetLastIndexSelected(size_t idx) { fLastIndexSelected = idx; }
454 
459  size_t GetLastHoverBin() const { return fLastHoverBin; }
460 
465  void SetLastHoverBin(size_t b) { fLastHoverBin = b; }
466 
467  // /**
468  // * @brief Open navigator from file.
469  // * @param filename File name.
470  // * @param branches Branches to open.
471  // * @param treename Tree name (default: "ngnt").
472  // * @return Pointer to opened NGnNavigator.
473  // */
474  // static NGnNavigator * Open(const std::string & filename, const std::string & branches = "",
475  // const std::string & treename = "ngnt");
476  //
477  // /**
478  // * @brief Open navigator from TTree.
479  // * @param tree Pointer to TTree.
480  // * @param branches Branches to open.
481  // * @param file Pointer to TFile.
482  // * @return Pointer to opened NGnNavigator.
483  // */
484  // static NGnNavigator * Open(TTree * tree, const std::string & branches = "", TFile * file = nullptr);
485 
486  private:
487  NGnTree * fGnTree{nullptr};
488  std::vector<std::string> fObjectNames{};
489  std::map<std::string, std::vector<TObject *>> fObjectContentMap{};
490  std::vector<std::string> fParameterNames{};
491  std::map<std::string, std::vector<double>> fParameterContentMap{};
492  std::map<std::string, std::vector<double>> fParameterErrorContentMap{};
493  std::vector<std::string> fObjectTypes{"TH1"};
494 
495  NGnNavigator * fParent{nullptr};
496  std::vector<NGnNavigator *> fChildren{};
497 
498  TH1 * fProjection{nullptr};
499  size_t fNLevels{1};
500  size_t fLevel{0};
501  std::vector<std::vector<int>> fLevels{};
502  size_t fNCells{0};
503  size_t fLastHoverBin{0};
504  size_t fLastIndexSelected{0};
505  Int_t fTrigger{kButton1Down};
506 
508  ClassDefOverride(NGnNavigator, 2);
510 };
511 } // namespace Ndmspc
512 #endif
Defines binning mapping and content for NDMSPC histograms.
Definition: NBinningDef.h:26
Navigator object for managing hierarchical data structures and projections.
Definition: NGnNavigator.h:22
void SetLevel(size_t l)
Set current level in hierarchy.
Definition: NGnNavigator.h:417
size_t GetNCells() const
Get number of cells in projection histogram.
Definition: NGnNavigator.h:435
std::vector< TObject * > GetObjects(const std::string &name) const
Get objects by name.
void SetChild(NGnNavigator *child, int index=-1)
Set child navigator at index.
void ResizeParameterContentMap(const std::string &name, int n)
Resize parameter content map for a given name.
Definition: NGnNavigator.h:310
std::vector< std::string > GetParameterNames() const
Get parameter names managed by navigator.
Definition: NGnNavigator.h:375
void SetObject(const std::string &name, TObject *obj, int index=-1)
Set object by name and index.
void SetLevels(const std::vector< std::vector< int >> &levels)
Set the levels using a vector of vectors of integers.
Definition: NGnNavigator.h:429
void SetChildrenSize(size_t n)
Set number of children.
Definition: NGnNavigator.h:196
void SetParameterNames(const std::vector< std::string > &names)
Set parameter names managed by navigator.
Definition: NGnNavigator.h:381
virtual TList * DrawSpectraByName(std::string parameterName, std::vector< std::string > projAxes, std::vector< double > minmax={0.05}, const std::string &minmaxMode="V", Option_t *option="") const
Draws spectra for the given parameter and projection axes.
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Handle execution of events (e.g., mouse, keyboard).
virtual void Print(Option_t *option="") const override
Print navigator information.
NGnNavigator * GetParent() const
Get parent navigator.
Definition: NGnNavigator.h:227
double GetParameterError(const std::string &name, int index=0) const
Retrieves a specific error value for a parameter.
void SetProjection(TH1 *h)
Set projection histogram.
Definition: NGnNavigator.h:393
NGnNavigator * fParent
Parent object.
Definition: NGnNavigator.h:495
virtual ~NGnNavigator()
Destructor.
std::vector< std::string > fParameterNames
Parameter names.
Definition: NGnNavigator.h:490
TH1 * GetProjection() const
Get projection histogram.
Definition: NGnNavigator.h:387
size_t fNLevels
Number of levels in the hierarchy.
Definition: NGnNavigator.h:499
virtual void Paint(Option_t *option="") override
Paint navigator objects.
void ResizeParameterErrorContentMap(const std::string &name, int n)
Resizes the error vector for a given parameter name.
Definition: NGnNavigator.h:346
virtual TList * DrawSpectra(std::string parameterName, std::vector< int > projIds, std::vector< double > minmax={0.05}, const std::string &minmaxMode="V", Option_t *option="") const
Draw spectra for a parameter.
virtual void Draw(Option_t *option="") override
Draw navigator objects.
std::map< std::string, std::vector< TObject * > > GetObjectContentMap() const
Get object content map.
Definition: NGnNavigator.h:249
void SetParameterError(const std::string &name, double value, int index=-1)
Sets a specific error value for a parameter.
std::vector< std::vector< int > > fLevels
Levels definition.
Definition: NGnNavigator.h:501
void SetLastIndexSelected(size_t idx)
Set last selected index.
Definition: NGnNavigator.h:453
TObject * GetObject(const std::string &name, int index=0) const
Get object by name and index.
std::vector< std::string > GetObjectNames() const
Get object names managed by navigator.
Definition: NGnNavigator.h:291
NGnNavigator * GetChild(size_t index) const
Get child navigator at index.
size_t fNCells
Number of cells in the projection histogram.
Definition: NGnNavigator.h:502
void Export(const std::string &filename, std::vector< std::string > objectNames, const std::string &wsUrl="", int timeoutMs=1000)
Export navigator data to file.
NGnNavigator(const char *name="GnNavigator", const char *title="Gn Navigator", std::vector< std::string > objectTypes={"TH1"})
Constructor.
NGnNavigator * Reshape(std::string binningName, std::vector< std::vector< int >> levels, size_t level=0, std::map< int, std::vector< int >> ranges={}, std::map< int, std::vector< int >> rangesBase={})
Reshape navigator using binning name and levels.
std::vector< std::string > fObjectTypes
Object types.
Definition: NGnNavigator.h:493
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Calculate distance to primitive for graphical selection.
void SetGnTree(NGnTree *tree)
Set NGnTree object pointer.
Definition: NGnNavigator.h:184
size_t fLastHoverBin
To avoid spamming the console on hover.
Definition: NGnNavigator.h:503
json GetInfoJson() const
Retrieves information about the navigator in JSON format.
size_t GetLevel() const
Get current level in hierarchy.
Definition: NGnNavigator.h:411
NGnTree * fGnTree
! Pointer to the NGnTree
Definition: NGnNavigator.h:487
size_t GetLastIndexSelected() const
Get last selected index.
Definition: NGnNavigator.h:447
std::map< std::string, std::vector< double > > fParameterContentMap
Parameter content map.
Definition: NGnNavigator.h:491
virtual TList * DrawSpectraAll(std::string parameterName, std::vector< double > minmax={0.05}, const std::string &minmaxMode="V", Option_t *option="") const
Draws all spectra for the given parameter.
size_t fLevel
Level of the object in the hierarchy.
Definition: NGnNavigator.h:500
void ExportToJson(json &j, NGnNavigator *obj, std::vector< std::string > objectNames)
Export navigator data to JSON.
std::vector< NGnNavigator * > fChildren
Children objects.
Definition: NGnNavigator.h:496
void SetNLevels(size_t n)
Set number of levels in hierarchy.
Definition: NGnNavigator.h:405
void SetNCells(size_t n)
Set number of cells in projection histogram.
Definition: NGnNavigator.h:441
std::map< std::string, std::vector< double > > fParameterErrorContentMap
Parameter error content map.
Definition: NGnNavigator.h:492
Int_t fTrigger
last triggered event
Definition: NGnNavigator.h:505
void SetParent(NGnNavigator *parent)
Set parent navigator.
Definition: NGnNavigator.h:243
std::vector< std::string > fObjectNames
Object names.
Definition: NGnNavigator.h:488
size_t GetLastHoverBin() const
Get last hovered bin index.
Definition: NGnNavigator.h:459
std::map< std::string, std::vector< double > > GetParameterErrorContentMap() const
Returns the map containing parameter error vectors for each parameter name.
Definition: NGnNavigator.h:339
void ResizeObjectContentMap(const std::string &name, size_t n)
Resize object content map for a given name.
Definition: NGnNavigator.h:256
void SetObjectNames(const std::vector< std::string > &names)
Set object names managed by navigator.
Definition: NGnNavigator.h:297
NGnTree * GetGnTree() const
Get pointer to NGnTree object.
Definition: NGnNavigator.h:178
void SetParameter(const std::string &name, double value, int index=-1)
Set parameter value by name and index.
size_t GetNLevels() const
Get number of levels in hierarchy.
Definition: NGnNavigator.h:399
double GetParameter(const std::string &name, int index=0) const
Get parameter value by name and index.
std::vector< double > GetParameters(const std::string &name) const
Get parameters by name.
std::map< std::string, std::vector< double > > GetParameterContentMap() const
Get parameter content map.
Definition: NGnNavigator.h:303
size_t fLastIndexSelected
last selected index in the object
Definition: NGnNavigator.h:504
void SetObjectTypes(const std::vector< std::string > &types)
Set object types managed by navigator.
Definition: NGnNavigator.h:285
std::vector< std::vector< int > > GetLevels() const
Get the current levels as a vector of vectors of integers.
Definition: NGnNavigator.h:423
std::vector< NGnNavigator * > GetChildren() const
Get vector of child navigators.
Definition: NGnNavigator.h:190
std::map< std::string, std::vector< TObject * > > fObjectContentMap
Object content map.
Definition: NGnNavigator.h:489
NGnNavigator * GetRoot() const
Returns the root parent of this NGnNavigator.
void SetLastHoverBin(size_t b)
Set last hovered bin index.
Definition: NGnNavigator.h:465
TH1 * fProjection
Projection histogram.
Definition: NGnNavigator.h:498
std::vector< double > GetParameterErrors(const std::string &name) const
Retrieves the error vector for a given parameter name.
NDMSPC tree object for managing multi-dimensional data storage and processing.
Definition: NGnTree.h:75