Quick ways of sorting events in a TChain needed

Hi list,

I need to find a fast method to sort events in a tchain according to a variable in the chain. The tchain consists of typically two 2GB root files, with a sum of about 500 000 events, so its a quite cpu-demanding task.

I have tried the sorting function attached below that uses the TMath::Sort-function to sort an array containing the variable that determines the order I would like the tree to be in (this array is extracted from the tree previously in the program). Events are then fetched from the tchain according to the sorted array and a new TTree is filled which then will be ordered wit respect to the sorting-variable. This function is very fast as long as it doesnt have to fetch events from different files in the tchain alternatively, but then it takes about 1 second per event (on my rather slow laptop, but anyway) and this is way to slow.

So my question: Is it possible to speed up this sorting-function somehow, or do you know a faster way to do this? Many thanks for your help!

cheers
Petter

void orbitsort(TTree *sorted,TTree *unsorted, Double_t *obts){
Int_t nentries=unsorted->GetEntries();
Int_t *index = new Int_t[nentries];
Int_t *index_pnt=index;
int ijk;
TMath::Sort(nentries, obts, index, 0);
for (ijk=0;ijkGetEntry(*index_pnt++);
sorted->Fill();
}
}

I will try to prepare an example in the coming days to do this job.
Could you post the result of TTree::Print for your Tree?

Rene

see the example in attachement and modify it according to your needs.
See the limitations inside. I have no time now to make it more general than
it is and remove the limitations.

Rene
treesort.C (1.71 KB)

Hi,

Thanks for your help! The output is included below.

root [5] tr->Print(“toponly”)


*Tree :stuck_out_tongue:hysics : TechmodelEventReader *
*Entries : 253314 : Total = 11960206655 bytes File Size = 2078290175 *

  •    :          : Tree compression factor =   5.76                       *
    

branch: Header 0
branch: fUniqueID 7595
branch: fBits 5102280
branch: Tracker 0
branch: fUniqueID 7595
branch: fBits 484690
branch: good0 8100
branch: DAQmode[12] 594122
branch: DSPnumber[12] 616303
branch: DATAlength[12] 5721706
branch: eventn[12] 1467500
branch: nclust[12] 597234
branch: cutc[12] 592799
branch: cutcl[12] 593249
branch: addrcluster[12][3] 11999079
branch: signcluster[12][3] 13092463
branch: fc[12] 583887
branch: compressiontime[12] 1439936
branch: fl5[12] 585192
branch: fl4[12] 585192
branch: fl3[12] 585192
branch: fl2[12] 585192
branch: fl1[12] 585192
branch: fl6[12] 585192
branch: checksum[12] 5500436
branch: crc[12] 585199
branch: TOTDATAlength 477911
branch: TrackerData 1057880322
branch: pnum[12] 603876
branch: cmdnum[12] 596321
branch: bid[12] 592746
branch: alarm[12] 585636
branch: aswr[12] 5619963
branch: unpackError 3715
branch: Anticounter 0
branch: fUniqueID 7595
branch: fBits 484690
branch: header[2][2] 479315
branch: status[2] 484223
branch: hitmap[2] 1055223
branch: regist[2][6] 562632
branch: shift[2][16] 2069287
branch: counters[2][16] 14853601
branch: coinc[2][8] 8476762
branch: trigg[2] 1504314
branch: clock[2][2] 2607172
branch: temp[2][2] 539290
branch: DAC[2][8] 531618
branch: CRC[2] 1606899
branch: CRCcheck[2] 484413
branch: unpackError 1731
branch: Calorimeter 0
branch: fUniqueID 7595
branch: fBits 484690
branch: iev 498650
branch: stwerr[4] 497296
branch: perror[4] 486817
branch: dexy[2][22][96] 618691105
branch: dexyc[2][22][96] 155193997
branch: base[2][22][6] 96109215
branch: calselftrig[4][7] 894548
branch: calIItrig[4] 574883
branch: calstriphit[4] 1670850
branch: calDSPtaberr[4] 488110
branch: calevnum[4] 1079598
branch: unpackError 1730
branch: Neutron 0
branch: fUniqueID 7595
branch: fBits 484690
branch: Records 3309497
branch: unpackError 3715
branch: S4 0
branch: fUniqueID 7595
branch: fBits 484690
branch: S4_REG_STATUS 1750
branch: S4_DATA 121500
branch: S4_CMD_NUM 1729
branch: S4_RESP_LENGHT 3765
branch: S4_OVERALL_CHKCODE 89439
branch: unpackError 1734
branch: Tof 0
branch: fUniqueID 7595
branch: fBits 484690
branch: tdcid[12] 614956
branch: evcount[12] 586089
branch: tdcmask[12] 586096
branch: adc[4][12] 10831482
branch: tdc[4][12] 11428407
branch: temp1[12] 812104
branch: temp2[12] 958018
branch: Trigger 0
branch: fUniqueID 7595
branch: fBits 484690
branch: evcount 485561
branch: pmtpl[3] 1372679
branch: trigrate[6] 640664
branch: dltime[2] 1534194
branch: s4calcount[2] 508200
branch: pmtcount1[24] 1588228
branch: pmtcount2[24] 1562853
branch: patternbusy[3] 540207
branch: patterntrig[6] 2391256
branch: trigconf 8246

[quote=“brun”]I will try to prepare an example in the coming days to do this job.
Could you post the result of TTree::Print for your Tree?

Rene[/quote]

The script that I sent you should work OK on your Tree.

Rene

Thanks! I really appreciate your help!

Petter