C++ TSelectors and PyROOT

Hi all,

I am running an analysis job steered in pyROOT, but with all relevant algorithms (such as TSelectors) written in C++ to enhance speed (are TPySelectors slower than TSelectors?).

If I have something such as

h_mass = new TH1F( "h_mass" , "Mass histogram" , 100 , 0 , 250 ); h_mass->GetXaxis()->SetTitle( "Mass (MeV)" ); fOutput->Add( h_mass );
in my TSelector so my generated histogram is copied in the Outputs List, how can I retrieve this output?

I run the TSelector by doing

So from Python I can directly access h_mass from the command line. This is not a good idea because if I have to call the same TSelector multiple times I will get into trouble.

My question is: is there any way to call GetOutputList or something similar from PyROOT so I can retrieve the outputs of my TSelector?

I have also tried to instantiate the TSelector in my PyROOT script to pass it then to the Process function, but since it needs a TSelector* and not a TSelector I get an error.

Thanks!
Albert

Albert,

the TPySelector is going to be slower for each individual call, b/c there’s a layer in between, but it is a fixed overhead, so its impact will depend on what happens in Process().

As for GetOutputList(), is this while running inside PROOF?

Cheers,
Wim

Hi Wim,

as for now, the script is not running in any PROOF envronment, but I am using TSelector because as soon as statistics rise I will switch to our PROOF Farm. It is just a matter of adding one line in the code, as I understand.

As for the TPySelector, I get that if the Process function performs a very complex (long) mathematical calculation the overhead will not be negligible, as Python is slower than C++ performing mathematical operations. And if operations in the Process method are short, then the fixed overhead will be large compared to the process time. Therefore, only for situations where the overall calculation time is not very large the tradeoff of the simplicity of Python vs the speed of C++ falls into the side of Python. I got this right?

Cheers,
Albert

Albert,

that is a pessimistic take on it, but yes qualitatively that would be correct. :slight_smile: Boundary cases will appear, though, if I/O is the major factor, or if you are selective in the Tree branches that you use.

For the single session, you should always be able to get the results through gROOT, but I’m simply not sure how PROOF collects the output list (my lack of knowledge of PROOF … ).

Cheers,
wim

Dear Albert,

In standard ROOT, after local processing, the output list can be accessed via the TTreePlayer object

  tree.Process("MyTSelector.C++", ...);
  mysel = ((TTreePlayer*)tree.GetPlayer())->GetSelectorFromFile();
  mysel->GetOutputList()->Print()

(The cast is needed because TTree::GetPlayer() returns a TVirtualTreePlayer object which does not have the GetSelectorFromFile() method; this will be simplified in the future).

I am not sure if anything like that be done in PyROOT.

PROOF saves the final output list in the TProofPlayer object owned by TProof. This list is accessible via TProof::GetOutputList() .

G. Ganis

Hi,

yes, so if that’s the recipe (using the player to get the selector through it), then that works with PyROOT in the exact same way, except of course that no cast is needed.

Cheers,
Wim