In my code I am using the following class:
class MyDouble {
public:
MyDouble(std::string n,std::string u,
int Nb,double mi,double ma)
: name(n),units(u),min(mi),max(ma),Nbins(Nb){}
const std::string name;
const std::string units;
const double min;
const double max;
const int Nbins;
void operator=(double v){this->value = v;}
void operator=(const MyDouble& v){this->value = v.value;}
operator double() const { return value; }
private:
double value;
};
The purpose of this class is to wrap a double value and attach all that is needed to create a histogram for this value (i.e. a name, min,max and number of bins). For anything else, objects of this class behave like simple doubles. For example:
MyDouble a("a","sec",100,0.0,100.0);
MyDouble b("b","sec",100,0.0,100.0);
MyDouble c("c","sec",100,0.0,200.0);
a = 5;
b = 20;
c = a+b;
Now I can automate creating histograms, without specifying names,min,max and number of bins each time. I.e. I can write functions like:
TH1* Make1DHistogram(a);
TH2* Make2DHistogram(a,b);
TH2* Make2DHistogram(b,c);
This all works quite nicely, but I have one small problem. When I save an Event that holds one of MyDoubles to a TTree and then try to see the values in a TBrowser, I get the error message:
[quote]Error in TClass::BuildRealData: Cannot find any ShowMembers function for MyDouble!
Warning in TSelectorDraw::ProcessFillObject: Not implemented for MyDouble[/quote]
As I understand, I have two options:
A) Implement needed methods in MyDouble. However, once the values are stored in a TTree, I do not need the additional information anymore and I rather would like to…
B) Not store MyDoubles in the TTree, but only the raw doubles. Is this possible somehow? To be more clear, I have an event that looks like this:
struct MyEvent {
MyDouble a;
};
But when writing to a TTree, the MyDouble should be converted to a plain double. Is this possible?