Hi all.
I’ve been struggling with this for a bit and decided to break down to ask the experts.
I have a TBits object as a member variable of my Header class, which is a member variable of my Event. I want to select events based upon whether or not a particular bit is set.
which should draw the histogram when the first bit is set. I’m not sure if this is working. It does draw a histogram for me.
But, I really want to test the 10th bit.
t->Draw(“someVariable”,“fMyHeader.fMyTBits.fAllBits & 0x200”)
Is that correct?
When I do this, I don’t get any events.
However, if I loop through all the events with TTree::GetEntry, and I explicitly test for TestBitNumber(10), I find events where it bit is set to 1. So, I’ve confirmed that I can find events in my tree where this bit has been set, but I can’t seem to get at that information when using TTree::Draw.
By the way, I’m using version 5.27.04.
I am attaching a set of files – modified Event.h/.cxx files found in the ‘test’ directory, and the Event.root file, which was generated from ./Event 100 3 99 1 (compression = 3, split = 99, fill = 1).
In the code, I added a TBits object to the Header class.
I then open the output file and try:
root [2] T->StartViewer()
File name : Event.root
root [3] T->Draw(“fEvtHdr.fTriggerBits”)
Error in TTreeFormula::Compile: Bad numerical expression : “fEvtHdr.fTriggerBits”
root [4] T->Draw(“event.fTriggerBits”) TCanvas::MakeDefCanvas: created default TCanvas with name c1
root [5] T->Draw(“fTracks.fTriggerBits”)
Clearly, the draw works for TBit objects that are stored in the Event class and the Tracks class (which is part o a TClonesArray). But, it doesn’t work for the TBit object stored in the Header.
Ahha!.. but, now if I recreate the file with the split level = 1 or 2, it works! Once I reach split level 3, I get the error “Bad numerical expression”.
So, in order for this to work, I have to direct ROOT not to split the TBits object in the Header class. Now it works as I suspect it was intended to work.
[quote]So, in order for this to work, I have to direct ROOT not to split the TBits object in the Header class. Now it works as I suspect it was intended to work. [/quote]Indeed, TTree::Draw can only (be guaranteed) to work with the TBits if it is not split (as you found out, it does sometimes works … but still).
[quote]t->Draw(“someVariable”,“fMyHeader.fMyTBits.fAllBits & 0x1”)
which should draw the histogram when the first bit is set. I’m not sure if this is working.[/quote]
It is not working … it is actually plotting when every 8th bit starting at 1 are set.
[quote]But, I really want to test the 10th bit.
t->Draw(“someVariable”,“fMyHeader.fMyTBits.fAllBits & 0x200”)
Is that correct?[/quote]No, it is not. The internal implementation of TBits is such that what you want is actually fAllBits[1]&0x2.
Those subtleties are yet another reason why, you ought to not split the TBits .