Using TBits in a TTree::Draw

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.

So, I have tried

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. 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.

Also, when I try
t->Draw(“fMyHeader.fMyTBits”)

it doesn’t draw a histogram.

Thanks!
Adam

Hi again.

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.

I suspect this might be a bug you wish to fix.

cheers! :slight_smile:
Adam
Event.cxx (14.6 KB)
Event.h (7.85 KB)
Event.root (445 KB)

Hi again.

I noticed that I can’t use the method in the Header to get a reference to the TBit object when using the TTree::Draw.

root [3] T->Draw(“fNtrack”,“fEvtHdr.GetTriggerBits().TestBitNumber(6)”)
Error in TTreeFormula::Compile: Bad numerical expression : “fEvtHdr.GetTriggerBits().TestBitNumber(6)”
(Long64_t)(-1)
root [4] T->Draw(“fNtrack”,“fEvtHdr.fTriggerBits.TestBitNumber(6)”)
(Long64_t)2

Is this the same issue that was reported here: TTree::Draw() using class method vs. attribute

I am using v5.27.04

Adam

Hi,

Your last example/problem works fine with the trunk.

Cheers,
Philippe.

[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).

Cheers,
Philippe.

[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 :slight_smile:.

Cheers,
Philippe.