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

     1  // Copyright ©2023 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", "test-tcanvas.root", "output ROOT file")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  
    23  	out, err := rtests.RunCxxROOT("gentcanvas", []byte(script), *root)
    24  	if err != nil {
    25  		log.Fatalf("could not run ROOT macro:\noutput:\n%v\nerror: %+v", string(out), err)
    26  	}
    27  }
    28  
    29  const script = `
    30  void gentcanvas(const char* fname) {
    31  	auto f = TFile::Open(fname, "RECREATE");
    32  	auto c = new TCanvas("c1", "c1-title", 300, 400);
    33  
    34  	c->AddExec("ex1", ".ls");
    35  	c->AddExec("ex2", ".ls");
    36  
    37  	const Int_t np = 5;
    38  	Double_t x[np]       = {0, 1, 2, 3, 4};
    39  	Double_t y[np]       = {0, 2, 4, 1, 3};
    40  
    41  	auto gr = new TGraph(np, x, y);
    42  	gr->Draw();
    43  	gr->Fit("pol1");
    44  
    45  	c->SetFixedAspectRatio();
    46  
    47  	f->WriteTObject(c);
    48  	f->Write();
    49  	f->Close();
    50  
    51  	exit(0);
    52  }
    53  `