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

     1  // Copyright ©2022 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-tgme.root", "output ROOT file")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  
    23  	out, err := rtests.RunCxxROOT("gentgme", []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  #include "TGraphMultiErrors.h"
    31  #include "TMultiGraph.h"
    32  #include "TGraph.h"
    33  #include "TGraphErrors.h"
    34  #include "TGraphAsymmErrors.h"
    35  
    36  #include "TFile.h"
    37  
    38  void gentgme(const char* fname) {
    39  	const Int_t np = 5;
    40  	Double_t x[np]       = {0, 1, 2, 3, 4};
    41  	Double_t y[np]       = {0, 2, 4, 1, 3};
    42  	Double_t exl[np]     = {0.3, 0.3, 0.3, 0.3, 0.3};
    43  	Double_t exh[np]     = {0.3, 0.3, 0.3, 0.3, 0.3};
    44  	Double_t eylstat[np] = {1, 0.5, 1, 0.5, 1};
    45  	Double_t eyhstat[np] = {0.5, 1, 0.5, 1, 2};
    46  	Double_t eylsys[np]  = {0.5, 0.4, 0.8, 0.3, 1.2};
    47  	Double_t eyhsys[np]  = {0.6, 0.7, 0.6, 0.4, 0.8};
    48  
    49  	auto gme = new TGraphMultiErrors(
    50  		"gme", "TGraphMultiErrors Example",
    51  		np, x, y, exl, exh, eylstat, eyhstat
    52  	);
    53  	gme->AddYError(np, eylsys, eyhsys);
    54  	gme->SetMarkerStyle(20);
    55  	gme->SetLineColor(kRed);
    56  	gme->GetAttLine(0)->SetLineColor(kRed);
    57  	gme->GetAttLine(1)->SetLineColor(kBlue);
    58  	gme->GetAttFill(1)->SetFillStyle(0);
    59  
    60  	auto f = TFile::Open(fname, "RECREATE");
    61  	f->WriteTObject(gme, "gme");
    62  
    63  	auto g1 = new TGraph(np, x, eylstat);
    64  	auto g2 = new TGraphErrors(np, x, y, exl, eylsys);
    65  	auto g3 = new TGraphAsymmErrors(np, x, y, exl, exh, eylstat, eyhstat);
    66  	auto mg = new TMultiGraph("mg", "multi-graph example");
    67  	mg->Add(g1);
    68  	mg->Add(g2);
    69  	mg->Add(g3);
    70  	mg->Fit("pol1", "FQ");
    71  	f->WriteTObject(mg, "mg");
    72  
    73  	f->Write();
    74  	f->Close();
    75  
    76  	exit(0);
    77  }
    78  `