Home | News | Documentation | Download

Use TClonesArrays in PyROOT


#1

Hello PyROOT experts,

How to implement this code snippet in python


void tclwrite()
{
   struct Prob{
	   Electron
	   Pion
	   Muon
	   Kaon
	   Proton
   }

   TFile f("tcl.root","recreate");
   f.SetCompressionLevel(1);
   TTree T("T","test tcl");
   TClonesArray *arr = new TClonesArray("Prob");
   TClonesArray &ar = *arr;
   T.Branch("tcl",&arr,256000);

   for (Int_t ev=0;ev<1000;ev++) {
      ar.Clear();
      Int_t nlines = Int_t(gRandom->Gaus(50,10));
      if(nlines < 0) nlines = 1;
      for (Int_t i=0;i<nlines;i++) {
         Float_t x1 = gRandom->Rndm();
         Float_t x2 = gRandom->Rndm();
         Float_t x3 = gRandom->Rndm();
         Float_t x4 = gRandom->Rndm();
         new(ar[i]) Prob(x1,x2,x3,x4);
      }
      T.Fill();
   }
   T.Print();
   T.Write();
}

Thank you in advance


#2

Dear @wellatiger,

What part of your code can I exactly help you with? For an example of how to write to a TTree in PyROOT, please see:

https://root.cern.ch/how/how-write-ttree-python

Let me know if you need further clarification.

Best,

Enric


#3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.