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

     1  // Copyright ©2026 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-tefficiency.root", "output ROOT file")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  
    23  	out, err := rtests.RunCxxROOT("gentefficiency", []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 "TEfficiency.h"
    31  
    32  void gentefficiency(const char* fname) {
    33  	auto eff1 = new TEfficiency("eff1", "Eff1D", 10, 0, 10);
    34  	auto eff2 = new TEfficiency("eff2", "Eff2D", 10, 0, 10, 10, 0, 20);
    35  	auto eff3 = new TEfficiency("eff3", "Eff3D", 10, 0, 10, 10, 0, 20, 10, 0, 30);
    36  
    37  	for (int i = 0; i < 1000; i++) {
    38  		Bool_t passed = gRandom->Uniform(2) <= 1;
    39  		Double_t x = gRandom->Uniform(10);
    40  		Double_t y = gRandom->Uniform(20);
    41  		Double_t z = gRandom->Uniform(30);
    42  		eff1->Fill(passed, x);
    43  		eff2->Fill(passed, x, y);
    44  		eff3->Fill(passed, x, y, z);
    45  	}
    46  
    47  	auto f = TFile::Open(fname, "RECREATE");
    48  	f->WriteTObject(eff1, "eff1");
    49  	f->WriteTObject(eff2, "eff2");
    50  	f->WriteTObject(eff3, "eff3");
    51  
    52  	f->Write();
    53  	f->Close();
    54  
    55  	exit(0);
    56  }
    57  `