Sorting Tree going Wrong


I’m having troubles trying to build a new Tree from sorting another Tree by increasing order of pT. I did procedures similar those ones described in the ROOT manual and also I looked for similar tasks here in the forum. However I’m facing a very strange thing. The original Tree contains branches of float vectors and I just take each component of the vector and store it in a branch of a new Tree. So, I do the sort over this new Tree. It happens that the sort is not fine at all. For branches which have the values differing in the integer part the sorting goes right. For instance, if the values are [3.134, 0.453, 6.349] they are sorted in the right increasing way [0.453, 3.134, 6.349]. Now, if they are [3.453, 3.134, 6.349] they are sorted as [3.453, 3.134, 6.349], the value 3.453 comes before the value 3.134! Seems like, when the values does not differ in their integer part, the sort method does not have effect. Below I have the piece of code I’m using. I appreciate any help, please.

    TTreeIndex *mc_index = (TTreeIndex*)mc_tmp_tree->GetTreeIndex();
    Long64_t* sindex = mc_index->GetIndex();
    for(Int_t j=0; j<mc_tmp_tree->GetEntries(); j++){
      cout<<"\tMC_pt: "<<tmp_trkParts_pt<<endl;


I think you can only sort integer values.


I think you can only sort integer values.[/quote]

Hi Adrian,

Thank you by reply! I think that is not the problem since in another 2 post here in the forum I saw people managing this method to sort pT (that is exactly what I’m doing) and pT is not a integer parameter. Actually I could not solve this and I needed to have this prompt. So, I change the algorithm and create my own way to sort the events (there are more code now and probably is not so fast as this method). But, If someone else can figure out what can be the problem I would like to know and test. Unfortunately the files I’m using are very big and I can not upload they here.


The TTreeIndex implementation in ROOT does indeed store only Long64_t values. The one solution is to multiply the pt by enough so that you get the precision you want/need. With the example you quoted, the followingmc_tmp_tree->BuildIndex("trkParts_pt*1e5");will be enough.