HighLAND
OutputManager.hxx
1 #ifndef OutputManager_h
2 #define OutputManager_h
3 
4 #include <string.h>
5 #include <stdio.h>
6 #include <iostream>
7 #include <map>
8 #include <vector>
9 #include <TROOT.h>
10 #include <TChain.h>
11 #include <TFile.h>
12 #include <TVector3.h>
13 #include <TLorentzVector.h>
14 #include <stdexcept>
15 
16 #include "BasicTypes.hxx"
17 #include "TreeManager.hxx"
18 #include "DocStringManager.hxx"
19 
20 /// Maximum number of special trees
21 const UInt_t NMAXSPECIALTREES = 20;
22 
23 /// Maximum size for vector or matrices
24 const UInt_t MAXVECTORSIZE=100;
25 
26 /// Maxim number of variables in the micro-trees
27 const UInt_t NMAXTREEVARS = 1000;
28 
29 /// Exception for if we try to fill outside the size of float_vector etc.
30 class OutOfBounds: public std::runtime_error {
31  public:
32  OutOfBounds() : std::runtime_error("OutOfBounds") {}
33 };
34 
36 
37 public:
38 
39  float_vector(const int n1){
40  _m = new float[n1];
41  _n1 =n1;
42  }
43  ~float_vector() {
44  if (_m) delete[] _m;
45  }
46 
47  void Ini(Float_t val){
48  for (UInt_t i = 0; i<num_rows(); i++) _m[i]=val;
49  }
50 
51  void Fill(int i, Float_t val){
52  if (i < 0 || i >= _n1) throw OutOfBounds();
53  _m[i]=val;
54 
55  }
56 
57  Float_t GetValue(int i) const{
58  if (i < 0 || i >= _n1) throw OutOfBounds();
59  return _m[i];
60  }
61 
62  float* GetAddress(){return _m;}
63  size_t num_rows(){return _n1;}
64 
65 protected:
66  Float_t *_m;
67  int _n1;
68 };
69 
71 
72 public:
73 
74  float_matrix(const int n1, const int n2){
75  _m = new float[n1*n2];
76  _n1 =n1;
77  _n2= n2;
78  }
79  ~float_matrix() {
80  if (_m) delete[] _m;
81  }
82 
83  void Ini(Float_t val){
84  for (UInt_t i = 0; i<num_rows(); i++)
85  for (UInt_t j = 0; j<num_cols(); j++)
86  _m[i*_n2+j]=val;
87  }
88 
89  void Fill(int i, int j, Float_t val){
90  if (i < 0 || i >= _n1) throw OutOfBounds();
91  if (j < 0 || j >= _n2) throw OutOfBounds();
92  _m[i*_n2+j]=val;
93  }
94 
95  Float_t GetValue(int i, int j) const{
96  if (i < 0 || i >= _n1) throw OutOfBounds();
97  if (j < 0 || j >= _n2) throw OutOfBounds();
98  return _m[i*_n2+j];
99  }
100 
101  float* GetAddress(){return _m;}
102  size_t num_rows(){return _n1;}
103  size_t num_cols(){return _n2;}
104 
105 protected:
106  Float_t *_m;
107  int _n1;
108  int _n2;
109 
110 };
111 
112 
114 
115 public:
116 
117  float_3Dmatrix(const int n1, const int n2, const int n3){
118  _m = new float[n1*n2*n3];
119  _n1 =n1;
120  _n2= n2;
121  _n3= n3;
122  }
123  ~float_3Dmatrix() {
124  if (_m) delete[] _m;
125  }
126 
127  void Ini(Float_t val){
128  for (UInt_t i = 0; i<num_rows1(); i++)
129  for (UInt_t j = 0; j<num_rows2(); j++)
130  for (UInt_t k = 0; k<num_rows3(); k++)
131  _m[i*_n3*_n2 + j*_n3 + k]=val;
132  }
133 
134  void Fill(int i, int j, int k, Float_t val){
135  if (i < 0 || i >= _n1) throw OutOfBounds();
136  if (j < 0 || j >= _n2) throw OutOfBounds();
137  if (k < 0 || k >= _n3) throw OutOfBounds();
138  _m[i*_n3*_n2 + j*_n3 + k]=val;
139  }
140  Float_t GetValue(int i, int j, int k) const{
141  if (i < 0 || i >= _n1) throw OutOfBounds();
142  if (j < 0 || j >= _n2) throw OutOfBounds();
143  if (k < 0 || k >= _n3) throw OutOfBounds();
144  return _m[i*_n3*_n2 + j*_n3 + k];
145  }
146  float* GetAddress(){return _m;}
147  size_t num_rows1(){return _n1;}
148  size_t num_rows2(){return _n2;}
149  size_t num_rows3(){return _n3;}
150 
151 protected:
152  Float_t *_m;
153  int _n1;
154  int _n2;
155  int _n3;
156 };
157 
158 
160 
161 public:
162 
163  double_vector(const int n1){
164  _m = new double[n1];
165  _n1 =n1;
166  }
167  ~double_vector() {
168  if (_m) delete[] _m;
169  }
170 
171  void Ini(Double_t val){
172  for (UInt_t i = 0; i<num_rows(); i++) _m[i]=val;
173  }
174 
175  void Fill(int i, double val){
176  if (i < 0 || i >= _n1) throw OutOfBounds();
177  _m[i]=val;
178  }
179  double GetValue(int i) const{
180  if (i < 0 || i >= _n1) throw OutOfBounds();
181  return _m[i];
182  }
183  double* GetAddress(){return _m;}
184  size_t num_rows(){return _n1;}
185 
186 protected:
187  double *_m;
188  int _n1;
189 };
190 
192 
193 public:
194 
195  double_matrix(const int n1, const int n2){
196  _m = new double[n1*n2];
197  _n1 =n1;
198  _n2= n2;
199  }
200  ~double_matrix() {
201  if (_m) delete[] _m;
202  }
203 
204  void Ini(Double_t val){
205  for (UInt_t i = 0; i<num_rows(); i++)
206  for (UInt_t j = 0; j<num_cols(); j++)
207  _m[i*_n2+j]=val;
208  }
209 
210  void Fill(int i, int j, double val){
211  if (i < 0 || i >= _n1) throw OutOfBounds();
212  if (j < 0 || j >= _n2) throw OutOfBounds();
213  _m[i*_n2+j]=val;
214  }
215  double GetValue(int i, int j) const{
216  if (i < 0 || i >= _n1) throw OutOfBounds();
217  if (j < 0 || j >= _n2) throw OutOfBounds();
218  return _m[i*_n2+j];
219  }
220  double* GetAddress(){return _m;}
221  size_t num_rows(){return _n1;}
222  size_t num_cols(){return _n2;}
223 
224 protected:
225  double *_m;
226  int _n1;
227  int _n2;
228 
229 };
230 
231 
233 
234 public:
235 
236  double_3Dmatrix(const int n1, const int n2, const int n3){
237  _m = new double[n1*n2*n3];
238  _n1 =n1;
239  _n2= n2;
240  _n3= n3;
241  }
242  ~double_3Dmatrix() {
243  if (_m) delete[] _m;
244  }
245 
246  void Ini(Double_t val){
247  for (UInt_t i = 0; i<num_rows1(); i++)
248  for (UInt_t j = 0; j<num_rows2(); j++)
249  for (UInt_t k = 0; k<num_rows3(); k++)
250  _m[i*_n3*_n2 + j*_n3 + k]=val;
251  }
252 
253  void Fill(int i, int j, int k, double val){
254  if (i < 0 || i >= _n1) throw OutOfBounds();
255  if (j < 0 || j >= _n2) throw OutOfBounds();
256  if (k < 0 || k >= _n3) throw OutOfBounds();
257  _m[i*_n3*_n2 + j*_n3 + k]=val;
258  }
259  double GetValue(int i, int j, int k) const{
260  if (i < 0 || i >= _n1) throw OutOfBounds();
261  if (j < 0 || j >= _n2) throw OutOfBounds();
262  if (k < 0 || k >= _n3) throw OutOfBounds();
263  return _m[i*_n3*_n2 + j*_n3 + k];
264  }
265  double* GetAddress(){return _m;}
266  size_t num_rows1(){return _n1;}
267  size_t num_rows2(){return _n2;}
268  size_t num_rows3(){return _n3;}
269 
270 protected:
271  double *_m;
272  int _n1;
273  int _n2;
274  int _n3;
275 };
276 
277 
279 
280 public:
281 
282  int_vector(const int n1){
283  _m = new int[n1];
284  _n1 =n1;
285  }
286  ~int_vector() {
287  if (_m) delete[] _m;
288  }
289 
290  void Ini(Int_t val){
291  for (UInt_t i = 0; i<num_rows(); i++) _m[i]=val;
292  }
293 
294  void Fill(int i, int val){
295  if (i < 0 || i >= _n1) throw OutOfBounds();
296  _m[i]=val;
297  }
298  int GetValue(int i) const{
299  if (i < 0 || i >= _n1) throw OutOfBounds();
300  return _m[i];
301  }
302  int* GetAddress(){return _m;}
303  size_t num_rows(){return _n1;}
304 
305 protected:
306  int *_m;
307  int _n1;
308 };
309 
310 
312 
313 public:
314 
315  int_matrix(const int n1, const int n2){
316  _m = new int[n1*n2];
317  _n1 =n1;
318  _n2= n2;
319  }
320  ~int_matrix() {
321  if (_m) delete[] _m;
322  }
323 
324  void Ini(Int_t val){
325  for (UInt_t i = 0; i<num_rows(); i++)
326  for (UInt_t j = 0; j<num_cols(); j++)
327  _m[i*_n2+j]=val;
328  }
329 
330  void Fill(int i, int j, int val){
331  if (i < 0 || i >= _n1) throw OutOfBounds();
332  if (j < 0 || j >= _n2) throw OutOfBounds();
333  _m[i*_n2+j]=val;
334  }
335  int GetValue(int i, int j) const{
336  if (i < 0 || i >= _n1) throw OutOfBounds();
337  if (j < 0 || j >= _n2) throw OutOfBounds();
338  return _m[i*_n2+j];
339  }
340  int* GetAddress(){return _m;}
341  size_t num_rows(){return _n1;}
342  size_t num_cols(){return _n2;}
343 
344 protected:
345  int *_m;
346  int _n1;
347  int _n2;
348 };
349 
351 
352 public:
353 
354  int_3Dmatrix(const int n1, const int n2, const int n3){
355  _m = new int[n1*n2*n3];
356  _n1 =n1;
357  _n2= n2;
358  _n3= n3;
359  }
360  ~int_3Dmatrix() {
361  if (_m) delete[] _m;
362  }
363 
364  void Ini(Int_t val){
365  for (UInt_t i = 0; i<num_rows1(); i++)
366  for (UInt_t j = 0; j<num_rows2(); j++)
367  for (UInt_t k = 0; k<num_rows3(); k++)
368  _m[i*_n3*_n2 + j*_n3 + k]=val;
369  }
370 
371  void Fill(int i, int j, int k, int val){
372  if (i < 0 || i >= _n1) throw OutOfBounds();
373  if (j < 0 || j >= _n2) throw OutOfBounds();
374  if (k < 0 || k >= _n3) throw OutOfBounds();
375  _m[i*_n3*_n2 + j*_n3 + k]=val;
376  }
377  int GetValue(int i, int j, int k) const{
378  if (i < 0 || i >= _n1) throw OutOfBounds();
379  if (j < 0 || j >= _n2) throw OutOfBounds();
380  if (k < 0 || k >= _n3) throw OutOfBounds();
381  return _m[i*_n3*_n2 + j*_n3 + k];
382  }
383  int* GetAddress(){return _m;}
384  size_t num_rows1(){return _n1;}
385  size_t num_rows2(){return _n2;}
386  size_t num_rows3(){return _n3;}
387 
388 protected:
389  int *_m;
390  int _n1;
391  int _n2;
392  int _n3;
393 };
394 
395 
396 class achar{
397 
398 public:
399 
400  achar(){
401  }
402  ~achar() {
403  }
404 
405  void Fill(const std::string& var){
406  strcpy(_m, var.c_str());
407  }
408  char* GetAddress(){return _m;}
409 
410 protected:
411  char _m[100];
412 };
413 
415 
416 public:
417 
418  // default constructor (required for char_matrix)
419  char_vector(){
420  _n1 = 0;
421  _m.clear();
422  }
423  char_vector(const int n1){
424  _m.resize(n1);
425  for (int i=0; i<n1; i++) _m[i] = "";
426  _n1 = n1;
427  }
428  ~char_vector() {
429  _m.clear();
430  }
431 
432  void Fill(int i, const char* val){
433  if (i < 0 || i >= _n1) throw OutOfBounds();
434  _m[i]=val;
435  }
436 
437  std::vector<std::string>* GetAddress(){
438  return &_m;
439  }
440  size_t num_rows(){return _n1;}
441 
442 protected:
443  std::vector<std::string> _m;
444  int _n1;
445 };
446 
447 #ifdef __CINT__
448 #pragma link C++ class std::vector<char_vector>+;
449 #endif
450 
452  friend class char_vector;
453 public:
454 
455  char_matrix(const int n1, const int n2){
456  _m.resize(n2);
457  for (int i=0; i<n2; i++)
458  _m[i] = char_vector(n1);
459  _n1= n1;
460  _n2= n2;
461  }
462  ~char_matrix() {
463  _m.clear();
464  }
465 
466  void Fill(int i, int j, const char* val){
467  if (i < 0 || i >= _n1) throw OutOfBounds();
468  if (j < 0 || j >= _n2) throw OutOfBounds();
469  _m[i].Fill(j,val);
470  }
471 
472  std::vector<char_vector>* GetAddress(){return &_m;}
473  size_t num_rows(){return _n1;}
474  size_t num_cols(){return _n2;}
475 
476 protected:
477  std::vector<char_vector> _m;
478  int _n1;
479  int _n2;
480 };
481 
482 /// This class is an easy interfice ROOT's TTree functionality.
483 /// It allows adding single variables to a tree, vectors, matrices, etc.
484 ///
485 /// TODO: This class needs to be documented properly.
487 public :
488 
489  OutputManager();
490  virtual ~OutputManager();
491 
492  virtual bool Initialize();
493  virtual bool InitializeEntry();
494  virtual void Finalize();
495 
496  void InitializeTrees(bool iniVars=true);
497  void InitializeTree(Int_t tree_index, bool iniVars=true);
498  void InitializeTree(){InitializeTree(GetCurrentTree());}
499 
500  std::string GetString(int a);
501  std::string GetSize(const std::string& counter_name, unsigned int size);
502 
503  /// Returns the variable name
504  const std::string& GetVarName(Int_t tree_index, Int_t var_index) const {return _tree_vars_all_vars[tree_index][var_index];}
505 
506  const std::string& GetVarName(Int_t var_index) const {return _tree_vars_all_vars[GetCurrentTree()][var_index];}
507 
508  /// Returns the counter name
509  const std::string& GetCounterName(Int_t tree_index, Int_t counter_index) const {return _tree_vars_all_counters[tree_index][counter_index];}
510 
511  const std::string& GetCounterName(Int_t counter_index) const {return _tree_vars_all_counters[GetCurrentTree()][counter_index];}
512 
513 
514  //--------- Operations with counters ------------
515 
516 
517  void AddCounter(Int_t tree_index, Int_t index, Int_t counter_index, const std::string& counter_name, int size=-1);
518  void AddCounter(Int_t tree_index, Int_t counter_index, const std::string& counter_name, int size=-1);
519 
520  void InitializeCounter(Int_t tree_name, Int_t counter_index);
521  void InitializeCounter(Int_t counter_index);
522 
523  void ResizeCounter(Int_t tree_index, Int_t counter_index, Int_t size);
524  void ResizeCounter(Int_t counter_index, int size);
525 
526  bool HasCounter(Int_t tree_name, Int_t counter_index);
527 
528  bool CheckCounterType(Int_t counter_index, Int_t indx, Int_t var_index);
529 
530  void IncrementCounter(Int_t counter_index){_tree_vars_counter[_current_tree][counter_index]++;}
531 
532  void IncrementCounterForVar(Int_t index){IncrementCounter(GetCounterIndexForVar(index));}
533 
534  Int_t GetCounterIndexForVar(Int_t index){return _link_var_to_counter[_current_tree][index];}
535 
536 
537  Int_t GetCounterValue(Int_t counter_index){return _tree_vars_counter[_current_tree][counter_index];}
538  Int_t GetCounterValue(Int_t tree_index, Int_t counter_index){return _tree_vars_counter[tree_index][counter_index];}
539  Int_t GetCounterValueForVar(Int_t index){return GetCounterValue(GetCounterIndexForVar(index));}
540  Int_t GetCounterValueForVar(Int_t tree_index, Int_t index){return GetCounterValue(tree_index,GetCounterIndexForVar(index));}
541 
542  bool GetFirstIndexFromCounter(Int_t index, Int_t& indx1);
543 
544  //--------- Adding variables to tree ------------
545 
546  void DeleteVar(Int_t tree_index, Int_t index);
547 
548 
549  /// Add a single variable to all trees
550  void AddVar( Int_t index, const std::string& name, const std::string& type, const std::string& doc, double ini=-9999);
551 
552  /// Add a single variable to a specific tree
553  void AddVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& doc, double ini=-9999);
554 
555  /// Add a vector variable to all trees
556  void AddVectorVar( Int_t index, const std::string& name, const std::string& type, const std::string& doc, Int_t counter_index, const std::string& counter_name, Int_t size= -MAXVECTORSIZE);
557 
558  /// Add a vector variable to a specific tree
559  void AddVectorVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& doc, Int_t counter_index, const std::string& counter_name, Int_t size= -MAXVECTORSIZE);
560 
561  /// Add a vector variable to all trees
562  void AddVectorVar( Int_t index, const std::string& name, const std::string& type, const std::string& doc, const int size);
563 
564  /// Add a vector variable to a specific tree
565  void AddVectorVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& doc, const int size);
566 
567  /// Add a matrix variable to all trees
568  void AddMatrixVar( Int_t index, const std::string& name, const std::string& type, const std::string& doc, Int_t counter_index, const std::string& counter_name, int size1=-MAXVECTORSIZE, int size2=-1);
569 
570  /// Add a matrix variable to a specific tree
571  void AddMatrixVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& doc, Int_t counter_index, const std::string& counter_name, int size1=-MAXVECTORSIZE, int size2=-1);
572 
573  /// Add a matrix variable to all trees
574  void AddMatrixVar( Int_t index, const std::string& name, const std::string& type, const std::string& doc, int size1=-MAXVECTORSIZE, int size2=-1);
575 
576  /// Add a matrix variable to a specific tree
577  void AddMatrixVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& doc, int size1=-MAXVECTORSIZE, int size2=-1);
578 
579  /// Add a 3D matrix variable to all trees
580  void Add3DMatrixVar( Int_t index, const std::string& name, const std::string& type, const std::string& doc, Int_t counter_index, const std::string& counter_name,
581  int size1=-MAXVECTORSIZE, int size2=-1, int size3=-1);
582  /// Add a 3D matrix variable to a specific tree
583  void Add3DMatrixVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& doc, Int_t counter_index, const std::string& counter_name,
584  int size1=-MAXVECTORSIZE, int size2=-1, int size3=-1);
585 
586  /// Add a single analysis variable to all trees
587  void AddToyVar( Int_t index, const std::string& name, const std::string& type, const std::string& docstring);
588 
589  /// Add a single analysis variable to a specific tree
590  void AddToyVar( Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& docstring);
591 
592  /// Add a vector analysis variable to all trees
593  void AddToyVectorVar( Int_t index, const std::string& name, const std::string& type, const std::string& docstring, int ncomp);
594 
595  /// Add a vector analysis variable to a specific tree
596  void AddToyVectorVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& docstring, int ncomp);
597 
598 
599  /// Add a matrix analysis variable to all trees
600  void AddToyMatrixVar( Int_t index, const std::string& name, const std::string& type, const std::string& docstring, int ncomp1, int ncomp2);
601 
602  /// Add a matrix analysis variable to a specific tree
603  void AddToyMatrixVar(Int_t tree_index, Int_t index, const std::string& name, const std::string& type, const std::string& docstring, int ncomp1, int ncomp2);
604 
605 
606 
607  //---------- Filling variables --------------
608 
609  void InitializeVar(Int_t index, Double_t ini);
610  void InitializeVectorVar(Int_t index, Double_t ini);
611  void InitializeMatrixVar(Int_t index, Double_t ini);
612 
613  /// Fill a single variable
614  void FillVar(Int_t index, Float_t var);
615  void FillVar(Int_t index, Double_t var);
616  void FillVar(Int_t index, Int_t var);
617  void FillVar(Int_t index, const std::string& var);
618 
619  /// Get the value of a var already filled (so to be used in another package)
620  Float_t GetVarValueF(Int_t index);
621  Double_t GetVarValueD(Int_t index);
622  Int_t GetVarValueI(Int_t index);
623 
624  /// Fill a vector variable
625  void FillVectorVar(Int_t index, Float_t var, Int_t indx=-1);
626  void FillVectorVar(Int_t index, Int_t var, Int_t indx=-1);
627  void FillVectorVar(Int_t index, Double_t var, Int_t indx=-1);
628  void FillVectorVar(Int_t index, const std::string& var, Int_t indx=-1);
629 
630  /// Fill a vector variable from array
631  void FillVectorVarFromArray(Int_t index, const Double_t var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillVectorVar(index,(Double_t)var[i] ,i);}
632  void FillVectorVarFromArray(Int_t index, const Float_t var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillVectorVar(index,(Float_t)var[i] ,i);}
633  void FillVectorVarFromArray(Int_t index, const Int_t var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillVectorVar(index,(Int_t)var[i] ,i);}
634  void FillVectorVarFromArray(Int_t index, const std::string var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillVectorVar(index,(const std::string)var[i],i);}
635 
636  /// Get the value of a var already filled (so to be used in another package)
637  Float_t GetVectorVarValueF(Int_t index, Int_t i1){return _tree_vars_float_vector [GetCurrentTree()][index]->GetValue(i1);}
638  Double_t GetVectorVarValueD(Int_t index, Int_t i1){return _tree_vars_double_vector[GetCurrentTree()][index]->GetValue(i1);}
639  Int_t GetVectorVarValueI(Int_t index, Int_t i1){return _tree_vars_int_vector [GetCurrentTree()][index]->GetValue(i1);}
640 
641  /// Fill a matrix variable
642  void FillMatrixVar(Int_t index, Float_t var, Int_t indx1, Int_t indx2);
643  void FillMatrixVar(Int_t index, Int_t var, Int_t indx1, Int_t indx2);
644  void FillMatrixVar(Int_t index, Double_t var, Int_t indx1, Int_t indx2);
645 
646  /// Fill a matrix variable from array
647  void FillMatrixVarFromArray(Int_t index, const Double_t var[], Int_t indx1, UInt_t size) {for (UInt_t i=0;i<size;i++) FillMatrixVar(index,(Double_t)var[i],indx1,i);}
648  void FillMatrixVarFromArray(Int_t index, const Float_t var[], Int_t indx1, UInt_t size) {for (UInt_t i=0;i<size;i++) FillMatrixVar(index,(Float_t)var[i] ,indx1,i);}
649  void FillMatrixVarFromArray(Int_t index, const Int_t var[], Int_t indx1, UInt_t size) {for (UInt_t i=0;i<size;i++) FillMatrixVar(index,(Int_t)var[i] ,indx1,i);}
650 
651  /// Fill a matrix variable from array
652  void FillMatrixVarFromArray(Int_t index, const Double_t var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillMatrixVar(index,(Double_t)var[i],-1,i);}
653  void FillMatrixVarFromArray(Int_t index, const Float_t var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillMatrixVar(index,(Float_t)var[i] ,-1,i);}
654  void FillMatrixVarFromArray(Int_t index, const Int_t var[], UInt_t size) {for (UInt_t i=0;i<size;i++) FillMatrixVar(index,(Int_t)var[i] ,-1,i);}
655 
656  /// Get the value of a var already filled (so to be used in another package)
657  Float_t GetMatrixVarValueF(Int_t index, Int_t i1, Int_t i2){return _tree_vars_float_matrix [GetCurrentTree()][index]->GetValue(i1,i2);}
658  Double_t GetMatrixVarValueD(Int_t index, Int_t i1, Int_t i2){return _tree_vars_double_matrix[GetCurrentTree()][index]->GetValue(i1,i2);}
659  Int_t GetMatrixVarValueI(Int_t index, Int_t i1, Int_t i2){return _tree_vars_int_matrix [GetCurrentTree()][index]->GetValue(i1,i2);}
660 
661  /// Fill a 3D matrix variable
662  void Fill3DMatrixVar(Int_t index, Float_t var, Int_t indx1, Int_t indx2, Int_t indx3);
663  void Fill3DMatrixVar(Int_t index, Int_t var, Int_t indx1, Int_t indx2, Int_t indx3);
664  void Fill3DMatrixVar(Int_t index, Double_t var, Int_t indx1, Int_t indx2, Int_t indx3);
665 
666  /// Fill a 3D matrix variable from array
667  void Fill3DMatrixVarFromArray(Int_t index, const Double_t var[], Int_t indx1, Int_t indx2, UInt_t size) {for (UInt_t i=0;i<size;i++) Fill3DMatrixVar(index,(Double_t)var[i],indx1,indx2,i);}
668  void Fill3DMatrixVarFromArray(Int_t index, const Float_t var[], Int_t indx1, Int_t indx2, UInt_t size) {for (UInt_t i=0;i<size;i++) Fill3DMatrixVar(index,(Float_t)var[i] ,indx1,indx2,i);}
669  void Fill3DMatrixVarFromArray(Int_t index, const Int_t var[], Int_t indx1, Int_t indx2, UInt_t size) {for (UInt_t i=0;i<size;i++) Fill3DMatrixVar(index,(Int_t)var[i] ,indx1,indx2,i);}
670 
671  /// Fill a single analysis variable
672  void FillToyVar(Int_t index, Int_t var);
673  void FillToyVar(Int_t index, Float_t var);
674  void FillToyVar(Int_t index, Double_t var);
675 
676  /// Get the value of a var already filled (so to be used in another package)
677  Float_t GetToyVarValueF(Int_t index){return GetVectorVarValueF(index, GetToyIndex());}
678  Double_t GetToyVarValueD(Int_t index){return GetVectorVarValueD(index, GetToyIndex());}
679  Int_t GetToyVarValueI(Int_t index){return GetVectorVarValueI(index, GetToyIndex());}
680 
681  /// Fill a vector analysis variable
682  void FillToyVectorVar(Int_t index, Int_t var, Int_t comp);
683  void FillToyVectorVar(Int_t index, Float_t var, Int_t comp);
684  void FillToyVectorVar(Int_t index, Double_t var, Int_t comp);
685 
686  /// Get the value of a var already filled (so to be used in another package)
687  Float_t GetToyVectorVarValueF(Int_t index, Int_t i1){return GetMatrixVarValueF(index, GetToyIndex(), i1);}
688  Double_t GetToyVectorVarValueD(Int_t index, Int_t i1){return GetMatrixVarValueD(index, GetToyIndex(), i1);}
689  Int_t GetToyVectorVarValueI(Int_t index, Int_t i1){return GetMatrixVarValueI(index, GetToyIndex(), i1);}
690 
691  /// Fill a matrix analysis variable
692  void FillToyMatrixVar(Int_t index, Int_t var, Int_t comp1, Int_t comp2);
693  void FillToyMatrixVar(Int_t index, Float_t var, Int_t comp1, Int_t comp2);
694  void FillToyMatrixVar(Int_t index, Double_t var, Int_t comp1, Int_t comp2);
695 
696 
697  //--------- Manage analysis dependent variables --------------
698 
699 
700  // Initialize the analysis variable
701  void InitializeAnalysisVar(Int_t index, Double_t ini);
702  void InitializeAnalysisVectorVar(Int_t index, Double_t ini);
703 
704  //--------- Tree operations ------------
705 
706  /// Fill a specific tree
707  void FillTree(Int_t tree_index);
708 
709  /// Fill the current tree
710  void FillTree(){FillTree(GetCurrentTree());}
711 
712  /// Write a specific tree into a file
713  void WriteTree(const std::string& file, const std::string& conf);
714 
715  /// Write all trees into a file
716  void WriteTrees(const std::string& file);
717 
718  /// Add a tree provided its index and name
719  void AddTreeWithName(Int_t tree_index, const std::string& tree_name, TTree* tree=NULL);
720 
721  /// open the output file
722  bool OpenOutputFile(const std::string& file);
723 
724  /// close the output file
725  void CloseOutputFile();
726 
727  /// Ensure that the variable 'name' hasn't been added to the tree with index tree_index
728  /// already. Keeps a record of names that it's seen in _tree_vars_all_vars.
729  bool ValidateVarNameAndIndex(Int_t tree_index, Int_t var_index, const std::string& var_name);
730 
731  /// Whether the given tree name (conf) is "special" or not. Special trees aren't
732  /// the normal micro-trees, and contain meta information, like the header or
733  /// config info, or RooTracker information.
734  bool IsSpecialTree(Int_t tree_index);
735 
736  //--------- functions to control different toy experiments ----------
737 
738  /// Set and gets the index of the current toy experiment
739  void SetToyIndex(Int_t index){_toy_index=index;}
740  Int_t GetToyIndex(){return _toy_index;}
741 
742  /// Sets and gets the number of toy experiments for a given configuration
743  void SetNToys(Int_t tree_index, int ntoys);
744 
745  /// Get the number of toys for a given tree
746  UInt_t GetNToys(Int_t tree_index){return GetCounterValue(tree_index,NTOYS);}
747 
748  /// Get the number of toys for the current tree
749  UInt_t GetNToys(){return GetCounterValue(NTOYS);}
750 
751 
752  void AddToyWeight(Double_t w){_toyWeights.push_back(w);}
753 
754  void FillMicroTrees();
755 
756 
757  void SetFillSingleTree(Int_t tree_index){_single_tree_fill=tree_index;}
758 
759  void SetFillAllTrees(){_single_tree_fill=-1;}
760 
761  // Check the type iof a given variable
762  void CheckVariableType(Int_t index, const std::string& dim, const std::string& type, Bool_t exist);
763 
764  void SetDocStringManager(DocStringManager* doc){_doc=doc;}
765 
766  DocStringManager& docstrings(){return *_doc;}
767 
768  protected:
769 
770  // Map of trees
771  std::string _default_docstring;
772 
773  DocStringManager* _doc;
774 
775  std::vector<Double_t> _toyWeights;
776 
777  /// current toy experiment index
779 
780 
781  Int_t _single_tree_fill;
782 
783 
784  // ----- Branches in the tree ---------
785 
786  /// The names of all variables added
787  std::vector< std::vector< std::string > > _tree_vars_all_vars;
788 
789  /// The names of all counters added
790  std::vector< std::vector< std::string > > _tree_vars_all_counters;
791 
792  /// Correspondece between a variable index and the counter index
793  std::vector< std::vector< Int_t > > _link_var_to_counter;
794 
795  /// The size of the counter: 0 for variable size vectors, >0 for fix size vectors
796  std::vector< std::vector< Int_t > > _tree_vars_counter_size;
797 
798  /// The counter it self
799  std::vector< std::vector< Int_t > > _tree_vars_counter;
800 
801  /// Single variables
802  std::vector< std::vector< Int_t > > _tree_vars_int;
803  std::vector< std::vector< Float_t > > _tree_vars_float;
804  std::vector< std::vector< Double_t > > _tree_vars_double;
805  std::vector< std::vector< achar > > _tree_vars_char;
806 
807  /// Vector variables (1 index)
808  std::vector< std::vector< int_vector* > > _tree_vars_int_vector;
809  std::vector< std::vector< float_vector* > > _tree_vars_float_vector;
810  std::vector< std::vector< double_vector* > > _tree_vars_double_vector;
811  std::vector< std::vector< char_vector* > > _tree_vars_char_vector;
812 
813  /// Matrix variables (2 indices)
814  std::vector< std::vector< int_matrix* > > _tree_vars_int_matrix;
815  std::vector< std::vector< float_matrix* > > _tree_vars_float_matrix;
816  std::vector< std::vector< double_matrix* > > _tree_vars_double_matrix;
817  std::vector< std::vector< char_matrix* > > _tree_vars_char_matrix;
818 
819  /// 3D matrix variables (3 indices)
820  std::vector< std::vector< int_3Dmatrix* > > _tree_vars_int_3Dmatrix;
821  std::vector< std::vector< float_3Dmatrix* > > _tree_vars_float_3Dmatrix;
822  std::vector< std::vector< double_3Dmatrix* > > _tree_vars_double_3Dmatrix;
823 
824 
825  /// The counter it self
826  std::vector< std::vector< Int_t > > _tree_vars_used_counter;
827 
828  /// Single variables
829  std::vector< std::vector< Int_t > > _tree_vars_used_int;
830  std::vector< std::vector< Int_t > > _tree_vars_used_float;
831  std::vector< std::vector< Int_t > > _tree_vars_used_double;
832  std::vector< std::vector< Int_t > > _tree_vars_used_char;
833 
834  /// Vector variables (1 index)
835  std::vector< std::vector< Int_t > > _tree_vars_used_int_vector;
836  std::vector< std::vector< Int_t > > _tree_vars_used_float_vector;
837  std::vector< std::vector< Int_t > > _tree_vars_used_double_vector;
838  std::vector< std::vector< Int_t > > _tree_vars_used_char_vector;
839 
840  /// Matrix variables (2 indices)
841  std::vector< std::vector< Int_t > > _tree_vars_used_int_matrix;
842  std::vector< std::vector< Int_t > > _tree_vars_used_float_matrix;
843  std::vector< std::vector< Int_t > > _tree_vars_used_double_matrix;
844  std::vector< std::vector< Int_t > > _tree_vars_used_char_matrix;
845 
846  /// 3D matrix variables (3 indices)
847  std::vector< std::vector< Int_t > > _tree_vars_used_int_3Dmatrix;
848  std::vector< std::vector< Int_t > > _tree_vars_used_float_3Dmatrix;
849  std::vector< std::vector< Int_t > > _tree_vars_used_double_3Dmatrix;
850 
851  /// ----- Vectors containing whether a given index is used or not
852 
853  /// Single variables
854  std::vector< std::vector< Bool_t > > _tree_vars_exist_int;
855  std::vector< std::vector< Bool_t > > _tree_vars_exist_float;
856  std::vector< std::vector< Bool_t > > _tree_vars_exist_double;
857  std::vector< std::vector< Bool_t > > _tree_vars_exist_char;
858 
859  /// Vector variables (1 index)
860  std::vector< std::vector< Bool_t > > _tree_vars_exist_int_vector;
861  std::vector< std::vector< Bool_t > > _tree_vars_exist_float_vector;
862  std::vector< std::vector< Bool_t > > _tree_vars_exist_double_vector;
863  std::vector< std::vector< Bool_t > > _tree_vars_exist_char_vector;
864 
865  /// Matrix variables (2 indices)
866  std::vector< std::vector< Bool_t > > _tree_vars_exist_int_matrix;
867  std::vector< std::vector< Bool_t > > _tree_vars_exist_float_matrix;
868  std::vector< std::vector< Bool_t > > _tree_vars_exist_double_matrix;
869  std::vector< std::vector< Bool_t > > _tree_vars_exist_char_matrix;
870 
871  /// 3D matrix variables (3 indices)
872  std::vector< std::vector< Bool_t > > _tree_vars_exist_int_3Dmatrix;
873  std::vector< std::vector< Bool_t > > _tree_vars_exist_float_3Dmatrix;
874  std::vector< std::vector< Bool_t > > _tree_vars_exist_double_3Dmatrix;
875 
876 
877 public:
878 
879  enum enumStandardMicroTrees_OutputManager{
880  NTOYS=0,
881  toy_weight,
882  toy_index,
883  enumStandardMicroTreesLast_OutputManager
884  };
885 
886  enum enumSpecialTrees{
887  config=0,
888  header,
889  truth,
890  NRooTrackerVtx,
891  GRooTrackerVtx,
892  RooTrackerVtx,
893  enumSpecialTreesLast
894  };
895 
896 };
897 
898 
899 #define AddVarF(out, name, doc) out.AddVar(name,#name,"F",doc,-9999);
900 #define AddVarI(out, name, doc) out.AddVar(name,#name,"I",doc,-9999);
901 #define AddVarC(out, name, doc) out.AddVar(name,#name,"C",doc,-9999);
902 #define AddVarD(out, name, doc) out.AddVar(name,#name,"D",doc,-9999);
903 
904 #define AddVarAndIniF(out, name, doc, ini) out.AddVar(name,#name,"F",doc,ini);
905 #define AddVarAndIniI(out, name, doc, ini) out.AddVar(name,#name,"I",doc,ini);
906 #define AddVarAnaIniC(out, name, doc, ini) out.AddVar(name,#name,"C",doc,ini);
907 #define AddVarAndIniD(out, name, doc, ini) out.AddVar(name,#name,"D",doc,ini);
908 
909 #define AddVarVF(out, name, doc, count) out.AddVectorVar(name,#name,"F",doc,count,#count);
910 #define AddVarVI(out, name, doc, count) out.AddVectorVar(name,#name,"I",doc,count,#count);
911 #define AddVarVC(out, name, doc, count) out.AddVectorVar(name,#name,"C",doc,count,#count);
912 #define AddVarVD(out, name, doc, count) out.AddVectorVar(name,#name,"D",doc,count,#count);
913 
914 #define AddVarMaxSizeVF(out, name, doc, count,size) out.AddVectorVar(name,#name,"F",doc,count,#count,-size);
915 #define AddVarMaxSizeVI(out, name, doc, count,size) out.AddVectorVar(name,#name,"I",doc,count,#count,-size);
916 #define AddVarMaxSizeVC(out, name, doc, count,size) out.AddVectorVar(name,#name,"C",doc,count,#count,-size);
917 #define AddVarMaxSizeVD(out, name, doc, count,size) out.AddVectorVar(name,#name,"D",doc,count,#count,-size);
918 
919 #define AddVarFixVF(out, name, doc, size) out.AddVectorVar(name,#name,"F",doc,size);
920 #define AddVarFixVI(out, name, doc, size) out.AddVectorVar(name,#name,"I",doc,size);
921 #define AddVarFixVC(out, name, doc, size) out.AddVectorVar(name,#name,"C",doc,size);
922 #define AddVarFixVD(out, name, doc, size) out.AddVectorVar(name,#name,"D",doc,size);
923 
924 #define AddVarMF(out, name, doc, count,size1,size2) out.AddMatrixVar(name,#name,"F",doc,count,#count,size1,size2);
925 #define AddVarMI(out, name, doc, count,size1,size2) out.AddMatrixVar(name,#name,"I",doc,count,#count,size1,size2);
926 #define AddVarMC(out, name, doc, count,size1,size2) out.AddMatrixVar(name,#name,"C",doc,count,#count,size1,size2);
927 #define AddVarMD(out, name, doc, count,size1,size2) out.AddMatrixVar(name,#name,"D",doc,count,#count,size1,size2);
928 
929 
930 #define AddVarFixMF(out, name, doc, size1,size2) out.AddMatrixVar(name,#name,"F",doc,size1,size2);
931 #define AddVarFixMI(out, name, doc, size1,size2) out.AddMatrixVar(name,#name,"I",doc,size1,size2);
932 #define AddVarFixMC(out, name, doc, size1,size2) out.AddMatrixVar(name,#name,"C",doc,size1,size2);
933 #define AddVarFixMD(out, name, doc, size1,size2) out.AddMatrixVar(name,#name,"D",doc,size1,size2);
934 
935 
936 #define AddVar3VF(out, name, doc) out.AddVectorVar(name,#name,"F",doc,3);
937 #define AddVar3VD(out, name, doc) out.AddVectorVar(name,#name,"D",doc,3);
938 
939 #define AddVar4VF(out, name, doc) out.AddVectorVar(name,#name,"F",doc,4);
940 #define AddVar4VD(out, name, doc) out.AddVectorVar(name,#name,"D",doc,4);
941 
942 #define AddVar3MF(out, name, doc, count) out.AddMatrixVar(name,#name,"F",doc,count,#count,-MAXVECTORSIZE,3);
943 #define AddVar3MD(out, name, doc, count) out.AddMatrixVar(name,#name,"D",doc,count,#count,-MAXVECTORSIZE,3);
944 
945 #define AddVar4MF(out, name, doc, count) out.AddMatrixVar(name,#name,"F",doc,count,#count,-MAXVECTORSIZE,4);
946 #define AddVar4MD(out, name, doc, count) out.AddMatrixVar(name,#name,"D",doc,count,#count,-MAXVECTORSIZE,4);
947 
948 
949 #define AddToyVarF(out, name, doc) out.AddToyVar(name,#name,"F",doc);
950 #define AddToyVarI(out, name, doc) out.AddToyVar(name,#name,"I",doc);
951 #define AddToyVarC(out, name, doc) out.AddToyVar(name,#name,"C",doc);
952 #define AddToyVarD(out, name, doc) out.AddToyVar(name,#name,"D",doc);
953 
954 #define AddToyVarVF(out, name, doc, size) out.AddToyVectorVar(name,#name,"F",doc,size);
955 #define AddToyVarVI(out, name, doc, size) out.AddToyVectorVar(name,#name,"I",doc,size);
956 #define AddToyVarVD(out, name, doc, size) out.AddToyVectorVar(name,#name,"D",doc,size);
957 
958 
959 #define AddTree(out, name, tree) out.AddTreeWithName(name,#name,tree);
960 
961 
962 #endif
963 
964 
std::vector< std::vector< int_3Dmatrix *> > _tree_vars_int_3Dmatrix
3D matrix variables (3 indices)
Float_t GetToyVarValueF(Int_t index)
Get the value of a var already filled (so to be used in another package)
std::vector< std::vector< Int_t > > _tree_vars_counter
The counter it self.
void FillMatrixVarFromArray(Int_t index, const Double_t var[], UInt_t size)
Fill a matrix variable from array.
const std::string & GetVarName(Int_t tree_index, Int_t var_index) const
Returns the variable name.
std::vector< std::vector< Int_t > > _tree_vars_used_counter
The counter it self.
std::vector< std::vector< int_matrix *> > _tree_vars_int_matrix
Matrix variables (2 indices)
Float_t GetToyVectorVarValueF(Int_t index, Int_t i1)
Get the value of a var already filled (so to be used in another package)
std::vector< std::vector< Int_t > > _link_var_to_counter
Correspondece between a variable index and the counter index.
void Fill3DMatrixVarFromArray(Int_t index, const Double_t var[], Int_t indx1, Int_t indx2, UInt_t size)
Fill a 3D matrix variable from array.
int _toy_index
current toy experiment index
void FillMatrixVarFromArray(Int_t index, const Double_t var[], Int_t indx1, UInt_t size)
Fill a matrix variable from array.
Exception for if we try to fill outside the size of float_vector etc.
std::vector< std::vector< Int_t > > _tree_vars_used_int_matrix
Matrix variables (2 indices)
void FillTree()
Fill the current tree.
Float_t GetMatrixVarValueF(Int_t index, Int_t i1, Int_t i2)
Get the value of a var already filled (so to be used in another package)
std::vector< std::vector< Int_t > > _tree_vars_used_int
Single variables.
std::vector< std::vector< std::string > > _tree_vars_all_counters
The names of all counters added.
std::vector< std::vector< Int_t > > _tree_vars_counter_size
The size of the counter: 0 for variable size vectors, >0 for fix size vectors.
UInt_t GetNToys(Int_t tree_index)
Get the number of toys for a given tree.
UInt_t GetNToys()
Get the number of toys for the current tree.
Float_t GetVectorVarValueF(Int_t index, Int_t i1)
Get the value of a var already filled (so to be used in another package)
std::vector< std::vector< int_vector *> > _tree_vars_int_vector
Vector variables (1 index)
std::vector< std::vector< Int_t > > _tree_vars_used_int_3Dmatrix
3D matrix variables (3 indices)
const std::string & GetCounterName(Int_t tree_index, Int_t counter_index) const
Returns the counter name.
std::vector< std::vector< std::string > > _tree_vars_all_vars
The names of all variables added.
void SetToyIndex(Int_t index)
Set and gets the index of the current toy experiment.
std::vector< std::vector< Bool_t > > _tree_vars_exist_int
–— Vectors containing whether a given index is used or not
std::vector< std::vector< Bool_t > > _tree_vars_exist_int_vector
Vector variables (1 index)
std::vector< std::vector< Int_t > > _tree_vars_used_int_vector
Vector variables (1 index)
std::vector< std::vector< Int_t > > _tree_vars_int
Single variables.
void FillVectorVarFromArray(Int_t index, const Double_t var[], UInt_t size)
Fill a vector variable from array.
std::vector< std::vector< Bool_t > > _tree_vars_exist_int_matrix
Matrix variables (2 indices)
std::vector< std::vector< Bool_t > > _tree_vars_exist_int_3Dmatrix
3D matrix variables (3 indices)