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

     1  // Copyright ©2024 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-tscatter.root", "output ROOT file")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  
    23  	out, err := rtests.RunCxxROOT("gentscatter", []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 gentscatter(const char* fname) {
    31  	auto f = TFile::Open(fname, "RECREATE");
    32  
    33  	const int n = 5;
    34  	double xs[n] = {0, 1, 2, 3, 4};
    35  	double ys[n] = {0, 2, 4, 6, 8};
    36  	double cs[n] = {1, 3, 5, 7, 9};
    37  	double ss[n] = {2, 4, 6, 8, 10};
    38  
    39  	auto s = new TScatter(n, xs, ys, cs, ss);
    40  	s->SetMarkerStyle(20);
    41  	s->SetMarkerColor(kRed);
    42  	s->SetTitle("Scatter plot;X;Y");
    43  	s->SetName("scatter");
    44  
    45  	s->Draw("A"); // generate underlying TH2F.
    46  	auto h = s->GetHistogram();
    47  	if (h == NULL) {
    48  		exit(1);
    49  	}
    50  
    51  	f->WriteTObject(s);
    52  	f->Write();
    53  	f->Close();
    54  
    55  	exit(0);
    56  }
    57  `