go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-tlv-tree.go (about)

     1  // Copyright ©2021 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build ignore
     6  
     7  package main
     8  
     9  import (
    10  	"flag"
    11  	"log"
    12  
    13  	"go-hep.org/x/hep/groot/internal/rtests"
    14  )
    15  
    16  var (
    17  	root  = flag.String("f", "tlv.root", "output ROOT file")
    18  	split = flag.Int("split", 0, "default split-level for TTree")
    19  )
    20  
    21  func main() {
    22  	flag.Parse()
    23  
    24  	out, err := rtests.RunCxxROOT("gentree", []byte(script), *root, *split)
    25  	if err != nil {
    26  		log.Fatalf("could not run ROOT macro:\noutput:\n%v\nerror: %+v", string(out), err)
    27  	}
    28  }
    29  
    30  const script = `
    31  #include "TLorentzVector.h"
    32  
    33  void gentree(const char* fname, int splitlvl = 99) {
    34  	int bufsize = 32000;
    35  	int evtmax = 10;
    36  
    37  	auto f = TFile::Open(fname, "RECREATE");
    38  	auto t = new TTree("tree", "my tree title");
    39  
    40  	{
    41  		TLorentzVector *p4 = new TLorentzVector;
    42  		p4->SetPxPyPzE(10, 20, 30, 40);
    43  		f->WriteTObject(p4, "tlv");
    44  	}
    45  
    46  	TLorentzVector *tlv = new TLorentzVector;
    47  
    48  	t->Branch("p4", &tlv, bufsize, splitlvl);
    49  
    50  	for (int i = 0; i != evtmax; i++) {
    51  		tlv->SetPxPyPzE(0+i, 1+i, 2+i, 3+i);
    52  		t->Fill();
    53  	}
    54  
    55  	f->Write();
    56  	f->Close();
    57  
    58  	exit(0);
    59  }
    60  `